我正在嘗試爲我的網站啓動註冊過程。我正在使用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文件? –