Django - 为什么不扭转工作?

时间:2012-12-15 05:05:47

标签: django reverse

我正在尝试将视图重定向到另一个视图,因此用户无法在不满足条件的情况下访问该视图。在这种情况下,密码更改成功。我也希望使用HttpResponseRedirect来实现这一点。

现在,我以前从未使用过逆转,但我认为这是做到这一点的方法。问题是我无法逆转工作。我收到以下错误:

在/ account / password /上的ViewDoesNotExist 无法导入查找adownload.main.views.foo。模块findadownload.main.views中不存在视图。

# URLS

from django.conf.urls import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings


#SANDY
from findadownload.sandy.views import *


#TRIVIARIA
from findadownload.trivia.views import *
from findadownload.accounts.views import *


# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'findadownload.main.views.presidium_home', name='presidium_home'),
    (r'^web/$', 'findadownload.main.views.web'),
    (r'^web/developers/$', sandy_developers),


    #SANDY (for findadownload!)
    (r'^get/sandy/$', get_sandy),
    (r'^get/sandy/download/$', get_sandy_download),
    (r'^sandy/register/$', sandy_registration),
    (r'^sandy/complete/$', sandy_complete),
    (r'^web/shared/$', sandy_shared_files),
    (r'^web/remove/all/$', sandy_remove_all),
    (r'^web/remove/(?P<file_id>\w+)/$', sandy_remove_file),
    (r'^about/$', 'findadownload.main.views.about'),
    (r'^pytech/$', 'findadownload.main.views.pytech'), 
    (r'^pytech/aboutus$', 'findadownload.main.views.pytech_about'),
    (r'^pytech/services$', 'findadownload.main.views.pytech_services'),
    (r'^pytech/support$', 'findadownload.main.views.pytech_support'),
    (r'^pytech/contactus$', 'findadownload.main.views.pytech_contact'),
    (r'^pytech/sitemap$', 'findadownload.main.views.pytech_sitemap'),
    (r'^pytech/search/$', 'findadownload.main.views.pytech_search'),
    (r'^presidium', 'findadownload.main.views.presidium_home'),


    #TRIVIARIA
    (r'^register/$', register),
    (r'^login/$', login_view, {'template': 'trivia/registration/login.html'}),
    (r'^logout/$', logout_view),
    (r'^trivia/$', submit_question, {'template': 'trivia/trivia_questions.html'}),
    (r'^challenges/$', submit_question, {'template': 'trivia/trivia_challenges.html'}),
    (r'^question/thanks/$', question_thanks),
    (r'^question/answer/$', submit_answer),
    (r'^question/answer/result/(\d+)/(.*)/$', answer_result),
    (r'^question/answer/challenge/$', challenge_answer),
    (r'^account/$', upload_avatar),
    (r'^account/password/$', password_change),
    url(r'^account/password/success/$', 'findadownload.accounts.views.password_success'),
    (r'^(?P<username>\w+)/$', view_user_profile, {'template': 'trivia/trivia_view_user_questions.html'}),
    (r'^(?P<username>\w+)/trivia/$', view_user_profile, {'template': 'trivia/trivia_view_user_questions.html'}),
    (r'^(?P<username>\w+)/challenges/$', view_user_profile, {'template': 'trivia/trivia_view_user_challenges.html'}),




    #FILE SHARING
    (r'^web/share/(?P<file_id>\w+)/$', sandy_download),
    (r'^web/report/(?P<file_id>\w+)/$', sandy_file_report),
    (r'^web/like/(?P<file_id>\w+)/$', like_download),
    #OTHER
    (r'^web/profile/$', 'findadownload.main.views.web_profile'),
    (r'^web/edit/$', 'findadownload.main.views.web_edit'),
    (r'^trivia/$', 'findadownload.main.views.trivia_home', {'template': 'trivia/registration/index.html'}),
    (r'^web/get/$', 'findadownload.main.views.web_get'),
    (r'^web/progress/$', 'findadownload.main.views.web_progress'),
    (r'^web/foo/$', 'findadownload.main.views.foo'),
    (r'^web/search/$', 'findadownload.main.views.web_search'),
    (r'^web/logout/$', 'findadownload.main.views.web_logout'),
    (r'^web/resend/$', 'findadownload.main.views.web_resend'),
    (r'^web/home/$', 'findadownload.main.views.web_home'),
    (r'^web/history/$', 'findadownload.main.views.web_history'),
    (r'^web/verify/(?P<link>\w+)/$', 'findadownload.main.views.web_activate'),
    (r'^web/help/(?P<username>\w+)/$', 'findadownload.main.views.web_help'),
    (r'^web/welcome/(?P<username>\w+)/$', 'findadownload.main.views.welcome'),
    (r'^web/terms/$', 'findadownload.main.views.web_terms'),
    (r'^web/privacy/$', 'findadownload.main.views.web_privacy'),
    (r'^web/signup/$', 'findadownload.main.views.web_signup'),
    (r'^web/login/$', 'findadownload.main.views.web_login'),
    (r'^test$', 'findadownload.main.views.test'),
    # url(r'^findadownload/', include('findadownload.foo.urls')),


    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)


if 1:
    urlpatterns += patterns('',
        url(r'^uploads/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,
            'show_indexes': True,
        }),
   )




urlpatterns += staticfiles_urlpatterns()



    # VIEWS

    from django.http import HttpResponse, HttpResponseRedirect
    from django.shortcuts import render_to_response
    from findadownload.accounts.forms import *
    from django.contrib.auth.models import User
    from django.contrib import auth
    from findadownload.accounts.models import *
    from django.core.urlresolvers import reverse
    from findadownload.trivia.models import *


    def password_success(request):
        return render_to_response('trivia/trivia_password_success.html')

    def password_change(request):
        if request.user.is_authenticated():
            # if for is submitted
            if request.method == 'POST':
                form = PasswordForm(user=request.user, data=request.POST)
                # for the avatar part
                if form.is_valid():
                    cd = form.cleaned_data
                    request.user.set_password(cd['confirm_password'])
                    request.user.save()`enter code here`
                    # redirect to profile page after POST
                    return HttpResponseRedirect(reverse('findadownload.accounts.views.password_success'))
            else:
                form = PasswordForm(user=request.user)

            # render empty form
            return render_to_response('trivia/trivia_password_change.html', {'form': form},
                                      context_instance=RequestContext(request))
        else:
            return HttpResponseRedirect('/login/?next=%s' % request.path)

1 个答案:

答案 0 :(得分:0)

你必须在你的网址中指定name个kwargs,在这种情况下:

url(r'^account/password/success/$', 'findadownload.accounts.views.password_success', name = 'password_success')

然后像这样使用反向:

return HttpResponseRedirect(reverse('password_success'))

你传递给reverse的是urlpatterns上的name kwarg。

编辑:

我能看到你urls.py的剩余部分。我认为问题不在reverse上,因为Django找不到名为foo的视图。

相关问题