[英]Mapping template folder in Django
我无法从该目录映射html文件,但是我已按照所有说明进行操作。
以下是我的项目urls.py:-
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
url(r'^articles/', include('article.urls')),
)
应用程式中的Views.py:-
from django.shortcuts import render_to_response
from article.models import Article
def articles(request):
return render_to_response('articles.html',{'articles':
Article.objects.all()})
def article(request, article_id=1):
return render_to_response('article.html',{'article':
Article.objects.get(id=article_id)})
应用中的Urls.py:
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^all/$', 'artilce.views.articles'),
url(r'^get/(?P<article_id>\d+)/$', 'article.view.article'),
)
Settings.py将模板文件夹的确切位置显示为:-
TEMPLATE_DIRS = (
'C:\Python27\Scripts\django_test\article\templates',
好心提醒。 它在404页上显示文章,但无法映射。
即使在Windows上,也需要对路径使用unix样式的正斜杠。 请参阅此处的文档页面: https : //docs.djangoproject.com/en/1.6/ref/settings/#template-dirs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.