如何获得django-user-account的基本工作示例?

时间:2015-01-03 12:14:04

标签: python-3.x django-users django-1.7

我按照django-user-accounts上的安装说明进行操作。

致电http://[mysite]/account/signup

我可以看到:{# This template intentionally left blank to satisfy test suites. Your project should always provide a site_base.html itself. #}(我认为这是一个好兆头,我稍后会添加我的基本模板。)

之后,我创建了一个应用:./manage.py startapp myapp_account ...并使用" Usage"中的最小代码填充它。上面提到的手册的页面,因为我想获得一个基本的工作注册/登录/输出。

现在我在拨打http://[mysite]/account/signup/时收到错误:

Exception Value:     'module' object has no attribute 'views'
Exception Location:  /var/www/venv/django_1/django_1/urls.py in <module>, line 10
Python Executable:   /var/www/venv/bin/python3.4

我的代码: urls.py (主要项目名为django_1):

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

urlpatterns = patterns('',
    # this is line 10 in my case:
    url(r'^account/signup/$', myapp_account.views.SignupView(),name="account_signup"),
    url(r'^account/', include('account.urls')),
)         

myapp_account / views.py:

import account.views
import account.forms
import myapp_account.forms

class SignupView(account.views.SignupView):

    form_class = myapp_account.forms.SignupForm

    def after_signup(self, form):
        self.create_profile(form)
        super(SignupView, self).after_signup(form)

    def create_profile(self, form):
        profile = self.created_user.get_profile()
        profile.birthdate = form.cleaned_data["birthdate"]
        profile.save()

class LoginView(account.views.LoginView):
    form_class = account.forms.LoginEmailForm

myapp_account / forms.py

from django import forms
from django.forms.extras.widgets import SelectDateWidget
import account.forms

class SignupForm(account.forms.SignupForm):
    birthdate = forms.DateField(widget=SelectDateWidget(years=range(1930, 2010)))

是否有一种更简单的方法可以让它正常工作并且正在逐步扩展用户帐户?

1 个答案:

答案 0 :(得分:0)

像往常一样,答案在手册中Django, Class-based views

  1. 直接导入基于班级的视图
  2. 直接在网址
  3. 中调用基于类的视图

    更新 urls.py (主要)

    from django.conf.urls import patterns, include, url
    from myapp_account.views import SignupView # <- import class based view 
    
    urlpatterns = patterns('',
        # call class based view directly:
        url(r'^account/signup/$', SignupView.as_view(), name="account_signup"),
        url(r'^account/', include('account.urls')),
    )
    

    如果某人将我指向django-user-accounts的良好示例,我仍然会感到高兴。