2013-02-16 75 views
0

我想在Django註冊的註冊頁面上添加一些額外的字段,如「城市」。我跟着這method,但形式不會呈現額外的字段「城市」和「條款和服務」的複選標記。另外,當我通過Django調試工具欄檢查視圖是否正確時,它會正確顯示其他字段。不知道爲什麼額外的字段不在表單上呈現。Django註冊額外字段不會呈現

Forms.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)) 

Urls.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'), 

回答

0

因爲你延長,而不是RegistrationFormTermsOfService,

RegistrationForm.base_fields.update(UserProfileForm.base_fields) 

使用

RegistrationFormTermsOfService.base_fields.update(UserProfileForm.base_fields)