Django: 20 html files: 20 TemplateViews and 20 URL patterns needed?

  • A+
Category:Languages

I have 20 Django simple "foo.html" template files.

Do I need 20 TemplateViews and 20 entries in url_patterns or is there a simpler solution?

 


You can have a path like path('pages/<str:page>, views.pages)

And then in the view do something similar to:

from django.template.loader import get_template from django.template import TemplateDoesNotExist  def pages(request, page):     template_name = f'your-app/{page}.html'     try:         get_template(template_name)         return render(request, template_name)     except TemplateDoesNotExist:         # returns 404 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: