2016-05-06 73 views
0

每一個,,我使用get_success_url()到底需要3個參數(給定2)

Django的註冊 - 終極版(1.4)

我的Django的註冊(Django的1.8), ,然而,,當我從未註冊的網絡將顯示錯誤enter image description here

,但在form_valid中的views.py,第43行它是編輯功能,它似乎不是關於寄存器?

views.py

@login_required 
def edit_thing(request, slug): 
# grab the object... 
    thing = ProductsTbl.objects.get(slug=slug) 
    if thing.user != request.user: 
     raise Http404 
# set the form we're using... 
    form_class = ProductsTblForm 
    if request.method == 'POST': 
# grab the data from the submitted form 
     form = form_class(data=request.POST,files=request.FILES,instance=thing)#**line 43** 
     if form.is_valid(): 
      # save the new data 
      form.save() 
      return redirect('thing_detail', slug=thing.slug) 
# otherwise just create the form 
    else: 
     form = form_class(instance=thing) 
# and render the template 
    return render(request, 'things/edit_thing.html', { 
     'thing': thing, 
     'form': form, 
    }) 

urls.py

from django.conf.urls import patterns, url,include 
from django.contrib import admin 
from django.views.generic import TemplateView 
from designer import views 
from designer.backends import MyRegistrationView 
from django.conf import settings 
from django.contrib.auth.views import (
    password_reset, 
    password_reset_done, 
    password_reset_confirm, 
    password_reset_complete, 
) 

.... 
urlpatterns = [ 
    .... 
    url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), 
    .... 
] 

registration_form.html

<h1>Registration Form</h1> 
<form role="form" action="" method="post"> 
{% csrf_token %} 
{{ form.as_p }} 
<input type="submit" value="Submit" /> 
</form> 
{% endblock content %} 

,,雖然得到這個錯誤,,我的數據庫的用戶名和密碼,,,仍然寫道。 任何一個可以告訴我,爲什麼我得到這個錯誤,,非常感謝你

backends.py

from registration.backends.simple.views import RegistrationView 

class MyRegistrationView(RegistrationView): 
    def get_success_url(self, request, user): 
# the named URL that we want to redirect to after # successful registration 
     return ('home') 
+2

請出示** **全面追蹤,如文本,而不是圖像。 – Alasdair

+0

我只是加了backends.py –

回答

2

get_success_url方法沒有考慮請求作爲一個參數。去掉它。

class MyRegistrationView(RegistrationView): 
    def get_success_url(self, user): 
     # the named URL that we want to redirect to after # successful registration 
     return ('home') 

在這種情況下,因爲你總是重定向到home視圖,您可以設置success_url代替:

class MyRegistrationView(RegistrationView): 
    success_url = 'home' 
+0

謝謝你,我刪除了請求後,它可以工作 –

3

Django中註冊,終極版RegistrationView已get_success_url定義爲這一點。

def get_success_url(self, user=None): 
    """ 
    Use the new user when constructing success_url. 
    """ 
    return super(RegistrationView, self).get_success_url() 

因此,似乎只有兩個參數將傳遞給該功能。然而在你的子類中,如果你有

def get_success_url(self, request, user): 
    # the named URL that we want to redirect to after # successful registration 
    return ('home') 

它有一個額外的請求參數,你不會收到。因此錯誤。

+0

非常感謝你 –

+1

很高興能有所幫助。 – e4c5

0

1.4版本get_success_url方法不帶請求作爲參數之後:

def get_success_url(self, user=None): 

然而,如果你確實需要處理請求的對象(例如你要記住,用戶從該決定重新頁面gister可作爲GET或POST參數傳遞)django的登記-終極版提供了非常方便的信號: registration.signals。user_registered

如下:

def remember_program_for_registration(sender, user, request, **kwargs): 
    [do some processing of the request object] 
相關問題