Reverse Django generic view, post_save_redirect; error 'included urlconf doesnt have any patterns'

后端 未结 4 1312
再見小時候
再見小時候 2021-02-06 17:01

I did see the other question titled \'how to use django reverse a generic view\' and \'django named urls, generic views\' however my question is a little different and I do not

4条回答
  •  名媛妹妹
    2021-02-06 17:36

    Here's a solution to the problem I found here: http://andr.in/2009/11/21/calling-reverse-in-django/

    I have pasted the code snippet below in case that link disappears:

    from django.conf.urls.defaults import *
    from django.core.urlresolvers import reverse
    from django.utils.functional import lazy
    from django.http import HttpResponse
    
    reverse_lazy = lazy(reverse, str)
    
    urlpatterns = patterns('',
    url(r'^comehere/', lambda request: HttpResponse('Welcome!'), name='comehere'),
    url(r'^$', 'django.views.generic.simple.redirect_to',
    {'url': reverse_lazy('comehere')}, name='root')
    )

提交回复
热议问题