Comments (2)
I assume Django automatically looks for a template called <app_name>/<model>_list.html
, which in this case would be cheeses/cheese_list.html
. Here <model>
is the model that is defined in CheesListView
.
If you change the name of the url to 'array', then this template doesn't change, because it doesn't depend on the url name. In order to wire the view to cheese_array.html
, you need to add template = 'cheeses/cheese_array
in CheeseListView
which will override the default.
from django-crash-starter.
I assume Django automatically looks for a template called <app_name>/_list.html, which in this case would be cheeses/cheese_list.html. Here is the model that is defined in CheesListView.
If you change the name of the url to 'array', then this template doesn't change, because it doesn't depend on the url name. In order to wire the view to cheese_array.html, you need to add template = 'cheeses/cheese_array in CheeseListView which will override the default.
You are partially correct in your answer.
The most complete answer would be:
The main logic to define the name of the template is implemented in the get_template_names
method of some views mixins classes.
The default implementation of the get_template_names
is defined on the TemplateResponseMixin
class.
The mixin classe SingleObjectTemplateResponseMixin
and MultipleObjectTemplateResponseMixin
extends the TemplateResponseMixin
implementation and overwrite it to add the concept of template_name_suffix
and add the logic of a model instance instrospection to dynamic obtain the model name or app name + model name.
The CreateView
, UpdateView
and DeleteView
simply compose with these mixin classes and modify template_name_suffix
.
The inheritance and composition hierarchy of django views can be a little complex to understand. Something that always helps you find out where things are coming from is to manually explore function calls using the debugger of your choice and use https://ccbv.co.uk/ as additional documentation.
from django-crash-starter.
Related Issues (20)
- project_slug is not automatically filled out from project_name
- Initial Update
- Auto-generate a default project_slug from project_name
- python manage.py check doesn't pass
- Generate a better starting README
- pylint_celery missing dependency
- Generate a Markdown README rather than RST
- Changing default language of 3rd party django apps
- RuntimeError: Model class shop.models.Category doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. HOT 2
- Dependabot can't evaluate your Python dependency files
- Migrate from the legacy dependabot configuration to the new dependabot config format
- Dependabot can't evaluate your Python dependency files
- Is it possible to create everycheese project code in the current directory? HOT 1
- Improve settings/production.py
- manage.py migrate import issue (EveryCheese) HOT 5
- Coverage.py seems to missing something
- django.db.utils.OperationalError: fe_sendauth: no password supplied HOT 2
- It seems a typo in file {{cookiecutter.project_slug}}/requirements/local.txt HOT 1
- Add Dependabot to ensure dependencies are up-to-date HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-crash-starter.