我得到:使用 blog.urls 中定义的 URLconf,Django 按以下顺序尝试了这些 URL 模式:^ ^$ ^ ^/(?P[a-zA-Z0-9]+) [name='view_blog_post']当前 URL duzeltme-yazisi/ 与其中任何一个都不匹配。
这个错误。这里有一些输出:
urls.py(在项目文件夹中):
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^', include('userside.urls')),
)
urls.py(在应用程序的文件夹中):
from django.conf.urls import patterns, include, url
urlpatterns = patterns('userside.views',
url(r'^$','index'),
url(r'^/(?P<postslug>[^\.]+)','userside.views.singlePost',name='view_blog_post'),
)
视图.py:
from userside.models import Post
from django.shortcuts import render_to_response
from django.template import RequestContext
def index(request):
post_list = Post.objects.all()
return render_to_response('userside/index.html',
{'post_list':post_list},
context_instance = RequestContext(request))
def singlePost(request,postslug):
post = Post.objects.get(slug=postslug)
context = {'post':post}
return render_to_response('userside/detail.html',context,context_instance = RequestContext(request))
模型.py:
from django.db import models
#from django.utils import timezone
from django.db.models import permalink
class Post(models.Model):
title = models.CharField(max_length = 100)
# date = models.DateTimeField(auto_now_add=True)
text = models.TextField()
slug = models.SlugField(unique=True)
def __unicode__(self):
return self.title
@permalink
def get_absolute_url(self):
return ('view_blog_post',None, {'postslug':self.slug})
这是我的 index.html 模板文件:
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/index.css" />
</head>
<body>
<h1>Hello Mars</h1>
<br>
{% if post_list %}
{% for x in post_list %}
<p><a href="/{{ x.slug }}/">{{ x.title }}</a></p>
<p>{{ x.text }}</p>
<hr>
{% endfor %}
{% else %}
<div class="center">No records! ( but looks like code works correctly!)</div>
{% endif %}
</body>
</html>
Django 版本:1.4
这里有什么问题?:/
谢谢你