我正在尝试为我的网站启动注册过程。我正在使用Python 3.3.5和Django 1.6。没有名为'forms'的模块Django
我收到一条错误消息,内容为No module named 'forms'
。我对Python/Django相当陌生。
这里是我的文件:
Views.py:
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.core.context_processors import csrf
from django.contrib.auth.forms import UserCreationForm
from forms import MyRegistrationForm
def register_user(request):
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
else:
form = MyRegistrationForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('register1.html', args)
def register_success(request):
return render_to_response('register_success.html')
Forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class MyRegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')
def save(self, commit=True):
user = super(MyRegistrationForm, self).save(commit=False)
user.email = self.cleaned_data['email']
# user.set_password(self.cleaned_data['password1'])
if commit:
user.save()
return user
的forms.py位于同一文件夹中views.py。我尝试从django.forms导入MyRegistrationForm但出现错误cannot import name MyRegistrationForm
。
该文件夹是否包含__ init __.py文件? –