0

ビューを別のビューにリダイレクトして、条件が満たされない限りユーザーがアクセスできないようにしようとしています。この場合、パスワードの変更は成功です。また、HttpResponseRedirect を使用してこれを実現したいと考えています。

さて、私はこれまでリバースを使用したことがありませんでしたが、これがその方法であると考えました. 問題は、逆に機能しないことです。次のエラーが表示されます。

ViewDoesNotExist at /account/password/ findadownload.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)
4

1 に答える 1

0

nameこの場合、URLにkwargsを指定する必要があります:

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

次に、次のように逆を使用します。

return HttpResponseRedirect(reverse('password_success'))

あなたが渡すのreverseは、nameurlpatterns の kwarg です。

編集:

あなたの の残りを見ることができますかurls.pyreverseDjango は という名前のビューを見つけることができないため、問題は on ではないと思いますfoo

于 2012-12-15T05:08:49.660 に答える