I am transforming my code to django and have many HTML files and serve them to user. So currently I write:
我正在将我的代码转换为django并拥有许多HTML文件并将其提供给用户。所以目前我写道:
urls.py:
urls.py:
urlpatterns = [
url(r'^1.html$', views.display1),
url(r'^2.html$', views.display2),
url(r'^3.html$', views.display2) ...
views.py:
views.py:
def display1(request):
return render(request,'1.html')
def display2(request):
return render(request,'2.html')
def display3(request):
return render(request,'3.html')
I am sure this is an extremely ugly way. What is the correct way to write such functionality in django? (what is the term for what I am looking for so that I can google it)
我确信这是一种非常难看的方式。在django中编写此类功能的正确方法是什么? (我要找的是什么术语,以便我可以谷歌)
1 个解决方案
#1
1
It's in the tutorial.
它在教程中。
urlpatterns = [
url(r'^(?P<page>\d+)\.html$', views.display)
]
...
...
def display(request, page):
verify(page) # Implementation left as an exercise for the reader
return render(request, '{}.html'.format(page))
#1
1
It's in the tutorial.
它在教程中。
urlpatterns = [
url(r'^(?P<page>\d+)\.html$', views.display)
]
...
...
def display(request, page):
verify(page) # Implementation left as an exercise for the reader
return render(request, '{}.html'.format(page))