GithubHelp home page GithubHelp logo

Comments (2)

mathemaat avatar mathemaat commented on July 30, 2024

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.

luzfcb avatar luzfcb commented on July 30, 2024

@mathemaat

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_namesis 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.