get_success_url() 正好需要 3 个参数(给定 2 个) [英] get_success_url() takes exactly 3 arguments (2 given)

查看:24
本文介绍了get_success_url() 正好需要 3 个参数(给定 2 个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每一个,我都在用

<块引用>

django-registration-redux (1.4)

对于我的 django 注册(django 1.8),但是,当我从未注册时,网络将显示错误

,但是form_valid中的views.py,第43行是编辑功能,好像不是寄存器的问题??

<块引用>

views.py

@login_requireddef edit_thing(请求,slug):# 抓取对象...thing = ProductsTbl.objects.get(slug=slug)如果 thing.user != request.user:提高Http404# 设置我们正在使用的表单...form_class = ProductsTblForm如果 request.method == 'POST':# 从提交的表单中获取数据form = form_class(data=request.POST,files=request.FILES,instance=thing)#**line 43**如果 form.is_valid():# 保存新数据表单.save()返回重定向('thing_detail',slug=thing.slug)# 否则只创建表单别的:form = form_class(实例=事物)# 并渲染模板返回渲染(请求,'东西/edit_thing.html',{'东西':东西,'形式':形式,})

<块引用>

urls.py

from django.conf.urls import patterns, url,include从 django.contrib 导入管理员从 django.views.generic 导入 TemplateView从设计器导入视图从designer.backends 导入MyRegistrationView从 django.conf 导入设置从 django.contrib.auth.views 导入(重设密码,密码重置完成,密码重置确认,密码重置完成,)....网址模式 = [....url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'),....]

<块引用>

registration_form.html

注册表

<form role="form" action="" method="post">{% csrf_token %}{{ form.as_p }}<input type="submit" value="Submit"/></表单>{% 端块含量 %}

,,虽然得到了这个错误,,我的数据库还是写了用户名和密码,,,.谁能告诉我为什么会出现这个错误,非常感谢

<块引用>

后端.py

from registration.backends.simple.views import RegistrationView类 MyRegistrationView(RegistrationView):def get_success_url(self, request, user):# 注册成功后我们要重定向到的命名 URL回家')

解决方案

get_success_url 方法不以请求为参数.删除它.

class MyRegistrationView(RegistrationView):def get_success_url(self, user):# 注册成功后我们要重定向到的命名 URL回家')

在这种情况下,由于您总是重定向到 home 视图,您可以设置 success_url:

class MyRegistrationView(RegistrationView):success_url = '家'

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 error

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

解决方案

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'

这篇关于get_success_url() 正好需要 3 个参数(给定 2 个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆