相关疑难解决方法(0)

Django-Registration和Django-Profile,使用您自己的自定义表单

我正在使用django-registration和django-profile来处理注册和配置文件.我想在注册时为用户创建个人资料.我创建了一个自定义注册表单,并使用以下教程将其添加到urls.py:

http://dewful.com/?p=70

本教程中的基本思想是覆盖默认注册表单以同时创建配置文件.

forms.py - 在我的个人资料应用中

from django import forms
from registration.forms import RegistrationForm
from django.utils.translation import ugettext_lazy as _
from profiles.models import UserProfile
from registration.models import RegistrationProfile

attrs_dict = { 'class': 'required' }

class UserRegistrationForm(RegistrationForm):
    city = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))

    def save(self, profile_callback=None):
        new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
        password=self.cleaned_data['password1'],
        email=self.cleaned_data['email'])
        new_profile = UserProfile(user=new_user, city=self.cleaned_data['city'])
        new_profile.save()
        return new_user
Run Code Online (Sandbox Code Playgroud)

在urls.py中

from profiles.forms import UserRegistrationForm
Run Code Online (Sandbox Code Playgroud)

url(r'^register/$',
                           register,
                           {'backend': 'registration.backends.default.DefaultBackend', 'form_class' : UserRegistrationForm},
                           name='registration_register'),
Run Code Online (Sandbox Code Playgroud)

显示表单,我可以在City中输入,但不会在DB中保存或创建条目.

python django profile registration django-forms

31
推荐指数
2
解决办法
4万
查看次数

关于使用django socialauth的困惑

http://github.com/uswaretech/Django-Socialauth/tree/master/socialauth/

我对如何使用它感到困惑.当然,我在底部阅读了笔记,但我是Django新手所以我需要一点手握住.

它的结构看起来像一个项目结构,因为它包含一个urls.py但我也知道应用程序也可以拥有它.它还有一个manage.py让我相信它是一个项目(加上子目录).

那么我应该将其中的部分内容集成到我现有的项目中吗?这不是一个应用程序,对吗?

README还提到了获取API密钥.因此,如果我想要一个标准界面,您点击google/yahoo徽标并通过Javascript将自己转发到您登录的身份验证页面,如果您尚未登录,请将您踢回自己的页面,我是否需要API钥匙?

任何其他特别提示表示赞赏.

openid django django-socialauth

6
推荐指数
1
解决办法
2951
查看次数