0
請幫忙解決問題。允許用戶訪問管理員?
我創建了一個表單來註冊用戶。我需要用戶在註冊adminpanel後訪問。此我試圖覆蓋場is_staff的值:
class RegistrationForm(UserCreationForm):
is_staff = forms.CharField(
default=True,
widget=forms.HiddenInput(),
)
class Meta:
model = User
fields = (
'username',
'email',
'password1',
'password2',
'is_staff',
)
觀點:
def registration(request):
"""
ajax refistration procedure
"""
result = False
form = RegistrationForm()
if request.method == 'POST' and request.is_ajax():
form = RegistrationForm(request.POST)
if form.is_valid():
try:
new_user = form.save()
except:
pass
else:
result = True
data = {
'result': result,
}
return HttpResponse(json.dumps(data), content_type='application/json')
的問題是,瀏覽器將顯示以下錯誤消息:
TypeError at/
__init__() got an unexpected keyword argument 'default' Request Method: GET Request URL: Django Version: 1.6.8
Exception Type: TypeError Exception Value:
__init__() got an unexpected keyword argument 'default' Exception Location: /home/kalinins/.virtualenvs/kinopom_project/kinopom_env/local/lib/python2.7/site-packages/django/forms/fields.py
in __init__, line 198
這個問題與允許用戶訪問管理界面沒有任何關係。 – 2014-11-06 13:10:12