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

How do I get a basic working example for django-user-account?

我按照 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" 页面中的最少代码填充它,因为我想获得基本的工作 register/login/out。

现在调用 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.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)))

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

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

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

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

  1. 直接导入基于 class 的视图
  2. 直接在url
  3. 中调用基于class的视图

已更新 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 示例,我仍然会很高兴。