get_success_url() takes exactly 3 arguments (2 giv

2019-03-05 03:32发布

every one ,, I am using

django-registration-redux (1.4)

for my django registration(django 1.8),,however ,,when never I registered the web will show the errorenter image description here

,,but the views.py in form_valid, line 43 it is the editing function,,it seems not about the register??

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 %}

,,though got this error ,,my databases still wrote in the user and password,,,. can any one tell me why I got this error,,thank you very much

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') 

3条回答
等我变得足够好
2楼-- · 2019-03-05 04:08

In django-registration-redux RegistrationView has get_success_url defined as this.

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

Thus it seems that only two parameters will be passed to that funciton. Yet in your subclass of if you have

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

Which has an extra request parameter which you are not going to recieve. hence the error.

查看更多
可以哭但决不认输i
3楼-- · 2019-03-05 04:26

after version 1.4 the get_success_url method does not take request as an argument:

def get_success_url(self, user=None):

However, if you do need to process the request object (for example you want to remember the page from which the user decided to register which may be passed as a get or post argument) django-registration-redux provides a very convenient signal: registration.signals.user_registered

as follows:

def remember_program_for_registration(sender, user, request, **kwargs):
    [do some processing of the request object]
查看更多
4楼-- · 2019-03-05 04:31

The get_success_url method does not take request as an argument. Remove it.

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

In this case, since you always redirect to the home view, you could set success_url instead:

class MyRegistrationView(RegistrationView):
    success_url = 'home'
查看更多
登录 后发表回答