Django 2.0问题解决了 注意空格和引号不要打错!!!
blog下 urls.py:
from django.urls import path, re_path
from . import views
app_name = 'blog'
urlpatterns = [
path('', views.index),
re_path('article/(?P<article_id>[0-9]+)$',views.article_page,name='article_page'),
]
myblog下urls.py:
from django.contrib import admin
from django.urls import path,include
import blog.views
urlpatterns = [
path('admin/', admin.site.urls),
path('blog/', include('blog.urls', namespace='blog')),
]
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--<h1>{{ article.title }}</h1>-->
<!--<h3>{{article.content}}</h3>-->
<h1><a href="">新文章</a>
</h1>
{% for article in articles %}
<a href="{% url 'blog:article_page' article.id %}">{{ article.title }}</a>
<br>
{% endfor %}
</body>
</html>
这里注意空格!!!!!!!!