相关疑难解决方法(0)

如何在django注册中注册后将用户重定向到特定网址?

所以我使用django-registration app为我的网站实现用户注册页面.我使用了Django的backends.simple视图,允许用户在注册后立即登录.我的问题是如何将它们重定向到与项目位于同一目录中的其他应用程序页面.

这是我的主要urls.py看起来像:

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',

    url(r'^accounts/', include('registration.backends.simple.urls')),
    url(r'^upload/', include('mysite.fileupload.urls')),
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^mysite/', include('mysite.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)),
)

import os
urlpatterns += patterns('',
        (r'^media/(.*)$', 'django.views.static.serve', {'document_root': os.path.join(os.path.abspath(os.path.dirname(__file__)), 'media')}),
)
Run Code Online (Sandbox Code Playgroud)

fileupload是我在项目目录mysite中拥有的其他应用程序的名称. …

django django-templates django-views django-registration

8
推荐指数
1
解决办法
7678
查看次数

Python/Django django-registration添加了一个额外的字段

我已经阅读了很多关于如何在使用Django-registration时添加额外字段的内容,例如此处,此处和此处.代码片段是:forms.py(来自注册应用)

class RegistrationForm(forms.Form):
    username = forms.RegexField(regex=r'^\w+$', max_length=30, widget=forms.TextInput(attrs=attrs_dict), label=_("Username"), error_messages={ 'invalid': _("This value must contain only letters, numbers and underscores.") })
    email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=75)), label=_("Email"))
    password1=forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False), label=_("Password"))
    institute=forms.CharField(max_length=50) #This is the new!
    password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False), label=_("Password (again)"))
    captcha = CaptchaField()
Run Code Online (Sandbox Code Playgroud)

我使用django的注册保存方法,它在默认的后端:

def register(self, request, **kwargs):
    username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
    if Site._meta.installed:
        site = Site.objects.get_current()
    else:
        site = RequestSite(request)
    new_user = RegistrationProfile.objects.create_inactive_user(username, email,
                                                                password, site)

    signals.user_registered.send(sender=self.__class__,
                                 user=new_user,
                                 request=request)
    return …
Run Code Online (Sandbox Code Playgroud)

django django-forms django-registration

5
推荐指数
2
解决办法
6633
查看次数