每一个人,我正在使用
django-registration-redux(1.4)
我的django注册(django 1.8),但是,当我从未注册过网络时会显示错误
,,但在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')
答案 0 :(得分:3)
在django-registration-redux 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')
有一个额外的请求参数,你不会接受。因此错误。
答案 1 :(得分: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'
答案 2 :(得分:0)
版本1.4之后,get_success_url方法不会将请求作为参数:
def get_success_url(self, user=None):
但是,如果您确实需要处理请求对象(例如,您想要记住用户决定注册的页面,可以将其作为get或post参数传递)django-registration-redux提供了非常方便的信号: registration.signals.user_registered
如下:
def remember_program_for_registration(sender, user, request, **kwargs):
[do some processing of the request object]