I am trying to initiate the registration process for my website. I am using Python 3.3.5 and Django 1.6.
I get the error No module named 'forms' . I am new to Python / Django.
Here are my files:
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']
form.py is in the same folder as view.py. I tried to import MyRegistrationForm from django.forms, but then a cannot import name MyRegistrationForm error occurs.
python django
edwards17
source share