python - django搭建个人博客单页文章无法进入,URL正确但仍留在当前页面,如何解决?
PHPz
PHPz 2017-04-17 17:11:51
0
1
390

新手提问
用django搭建个人博客过程中从主页面点击文章标题,不能进入单页文章页面仍然留在当前。但是URL没错从blog/变成blog/3.

部分代码如下:

视图函数

def page(request, article_id): try: post = Article.objects.get(id=str(article_id)) except Article.DoesNotExist: raise Http404('Article does not exists') return render(request, 'page.html', {'post': post})

url设置

url(r'^blog/(?P\d+)/$', 'article.views.page', name='page')

模板

 {% for post in post_list %} 

{{ post.title }}

{{ post.content }}

{% endfor %} {% block content %}

{{ post.title }}

{{ post.content }}

{% endblock %}

问题就是文章单页无法进入,请问如何解决?

感觉好像是render()函数找不到单页的page.html

PHPz
PHPz

学习是最好的投资!

reply all (1)
洪涛
url(r'^blog/', 'article.views.blog', name='blog')

Changed to:

url(r'^blog/$', 'article.views.blog', name='blog')

$是正则表达式中匹配结尾的符号,不加这个的话,blog/3也会导向blogThis view

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!