簡體   English   中英

Django模板不顯示

[英]Django template not displaying

我有一個關於頁面的模板,拒絕顯示。 我可能在做一些愚蠢的事情,但是我無法弄清楚為什么,這讓我發瘋了!

views.py的一部分:

# About view
def about(request):
    return render(request, 'blog/about.html')

urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin
from blog.views import post as blog_post
from blog.views import profile as blog_profile
admin.autodiscover()
urlpatterns = patterns('',

url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'blog.views.index'),
url(r'^about/$', 'blog.views.about'),
url(r'^profiles/$', 'blog.views.profile_index'),
url(r'^profiles/(?P<profile_url>[\w\-]+)/$', blog_profile, name = 'blog_profile'),
url(r'^(?P<category>[\w\-]+)/$', 'blog.views.categoryIndex'),
url(r'^(?P<category>[\w\-]+)/(?P<slug>[\w\-]+)/$', blog_post, name = 'blog_post')
)

關於模板(不包括base.html):

{% extends 'base.html' %}
{% block title %} About {% endblock %}
{% block content %}
<h1>About</h1>
{% endblock %}

使用Django 1.6.5

試圖瀏覽至mysite.com/about/

模板層次結構:

templates
    base.html
    blog
        about.html
        ....

如果您的模板目錄位於項目的根目錄下,則可能需要將以下內容添加到settings.py

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)

我已經解決了這個問題,以下網址卻與About頁面匹配:

url(r'^(?P<category>[\w\-]+)/$', 'blog.views.categoryIndex'),

刪除它可以解決問題並顯示關於頁面。 本頁說明有關url訂購的信息http://www.webforefront.com/django/regexpdjangourls.html

由於我的About URL在沖突的URL之前列出,因此被跳過了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM