私はジャンゴの簡単な登録フォームで立ち往生しています。登録フォームに入力すると、次のエラーが表示されます。
ValueError at /register/
The given username must be set
Request Method:POST
Request URL:http://127.0.0.1:8000/register/
Django Version:1.4
Exception Type:ValueError
Exception Value:The given username must be set
これが私のviews.pyです:
def register_page(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data['username'],
password=form.cleaned_data['password1'],
email=form.cleaned_data['email']
)
return HttpResponseRedirect('/register/success/')
else:
form = RegistrationForm()
variables = RequestContext(request, {'form': form
})
return render_to_response(
'registration/register.html',
variables
)
これは私の登録テンプレートです:
{% extends "base.html" %}
{% block title %}User Registration{% endblock %}
{% block head %}User Registration{% endblock %}
{% block content %}
<form method="post" action=".">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="register" />
</form>
{% endblock %}
そして私のURLパターン:
urlpatterns = patterns('',
(r'^$', main_page),
(r'^user/(\w+)/$', user_page),
(r'^login/$', 'django.contrib.auth.views.login'),
(r'^logout/$', logout_page),
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': site_media}),
(r'^register/$', register_page),
(r'^register/success/$', direct_to_template,
{'template': 'registration/register_success.html'}),
)
この問題については何も見つかりません。いくつかのガイダンスをいただければ幸いです。私はDjangoが初めてです。