Django创建用户基础

时间:2014-05-06 16:37:31

标签: python django

我是Django(1.5)的新手,并且在基本的东西上陷入困境。我尝试使用以下代码创建用户。 VIEW:

from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib import auth
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

def sign_up(request):

    if request.POST:
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = User.objects.create_user(username=username, password=password)
        user.save()
        return HttpResponseRedirect(reverse('account:login'))

    args = {}
    args.update(csrf(request))
    args['form'] = UserCreationForm()

    return render_to_response('account/sign_up.html', args, context_instance=RequestContext(request))

ACCORDANT TEMPLATE:

<html>

...

<div id="sign_up"> {% block extension1 %} 
    </form action="/account/sign_up/" method="post"> {% csrf_token %}
        {{ form }} <br/>
        <input type="submit" value="Sign up"/>
    </form> {% endblock %}
</div>

如果我按下“注册”按钮,则没有任何反应。我错过了什么基本的东西。我会讲一个关于这一点的小课。感谢。

0 个答案:

没有答案