我正在尝试在 Django-registration 的注册页面上添加一些额外的字段,例如“城市”。我遵循了这种方法,但表单没有呈现额外的字段“城市”和“条款和服务”复选标记。此外,当我通过 Django 调试工具栏检查视图是否正确时,它会正确显示附加字段。不知道为什么额外的字段没有呈现在表单上。
表格.py
from django.contrib.gis import forms from django.contrib.auth.models import User from django.db.models import Q from dirapp.models import UserProfile from django import forms from registration.forms import RegistrationForm, RegistrationFormTermsOfService from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ from registration.models import RegistrationProfile from forms import * class UserProfileForm(forms.ModelForm): class Meta: model = UserProfile exclude = ('user') widgets = { 'point': forms.HiddenInput(), } RegistrationForm.base_fields.update(UserProfileForm.base_fields) attrs_dict = { 'class': 'required' } class UserRegistrationForm(RegistrationFormTermsOfService): city = forms.CharField(max_length=3, label='whatisyourcity', widget=forms.TextInput(attrs=attrs_dict))
网址.py
from django.conf.urls.defaults import *
from django.views.generic import *
from django.conf import settings
from django.conf.urls.static import static
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
#from companies.models import Lead,Company
from dirapp.views import index, user_profile_crud, user_profile, add_listing, listing_detail, edit_listing, place_query, lead_detail, software_detail, add_vote_soft, software_list, add_classified, classified_detail,classified_list
from dirapp.models import UserProfile, Listing,Software,classified
admin.autodiscover()
from django.contrib.auth.decorators import login_required
from django.views.generic import list_detail
from djangoratings.views import AddRatingFromModel
from dirapp.forms import UserRegistrationForm
from registration.views import register
import registration.backends.default.urls as regUrls
listing_list = {"queryset":Listing.objects.all()}
urlpatterns = patterns('',
# 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)),
#url(r'^contact/$', login_required(TemplateView.as_view(template_name="companies/contact.html"))),
url(r'^$',index,name='index'),
url(r'^accounts/vendor-register/$', register, { 'backend': 'registration.backends.default.DefaultBackend','form_class':UserRegistrationForm}, name='registration_register'),
url(r'^accounts/', include(regUrls)),
url(r'^profile/$', user_profile, name='user-profile-view'),
url(r'^profile/edit/$', user_profile_crud, name ='user-profile-crud'),