我已经看过几个关于这个问题的相关问题,但到目前为止还没有一个问题有助于解决我的问题。
我在这个项目中创建了一个项目“mysite”和一个app,恰当地称为“app”。 mysite.urls看起来像这样:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('app.urls', namespace='app')),
]
app.urls
from django.conf.urls import include, url
from app import views
urlpatterns = [
url(r'^$', views.home),
url(r'^hello/$', views.students),
]
app.views
from django.shortcuts import render
def home(request):
return render(request, "base.html")
def students(request):
return render(request, "students.html")
app.templates.base.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>My site</title>
</head>
<body>
<h1>My site</h1>
<ul>
<li>
<a href="{% url 'app:students' %}">Students</a>
</li>
<ul>
<p>Thanks for visiting my site.</p>
<!-- {% endblock %} -->
</body>
</html>
django错误消息表明它与行
有关<a href="{% url 'app:students' %}">Students</a>
但我似乎无法弄明白。任何帮助将不胜感激
答案 0 :(得分:0)
您还没有将app
的网址命名为
# app.urls
urlpatterns = [
url(r'^$', views.home, name="home"),
url(r'^hello/$', views.students, name="students"),
]