1
我在我的博客應用程序中創建一個創建視圖來創建一個帖子。在 創建視圖我使用了函數get_success_url。我希望當我創建 的帖子時,它會重定向到blog_post_list。^hNoReverseMatch Django,get_success_url在CreateView
我得到的錯誤:NoReverseMatch
我猜它做某事與URL模式。
main urls.py
from django.conf.urls import url, include
from django.contrib import admin
from blog.views import AboutPageView, ContactPageView
urlpatterns = [
url(r'', include('blog.urls', namespace='posts')),
url(r'^blog/', include('blog.urls', namespace='posts')),
url(r'^about/$', AboutPageView.as_view(), name='about'),
url(r'^contact/$', ContactPageView.as_view(), name='contact'),
#admin and login
url(r'^admin/', admin.site.urls),
]
網址博客應用在blogapp
from django.conf.urls import url
from .views import blog_postListView, blog_postDetailView, blog_postCreateView
urlpatterns = [
url(r'^$', blog_postListView.as_view(), name='blog_post_list'),
url(r'^create/', blog_postCreateView.as_view(), name='blog_post_create'),
url(r'^(?P<slug>[-\w]+)$', blog_postDetailView.as_view(), name='detail'),
]
意見
class blog_postCreateView(CreateView):
#model = blog_post
form_class = blog_postForm
template_name = "form.html"
#fields = ["title", "content"]
def get_success_url(self):
return reverse("blog_post_list")
謝謝了很多:) 將肯定了解沒有反向匹配的鏈接,你救了我的時間 歡呼聲,感謝您的幫助 –
@ RobertF。 - 不用擔心,享受 – Sayse