Reputation: 2419
I'm getting a strange import error when trying to import a module "rememberMe" in view into forms.py though the module exists. (same import statement in shell works fine).
from django import forms
from models import UserAccount, SessionLog
from django.shortcuts import *
from view import rememberMe
from view import loginUser
class loginForm(forms.Form):
username = forms.CharField(max_length=20, min_length=5, error_messages={'required':'Username is required'})
password = forms.CharField(max_length=20, min_length=8, error_messages={'required':'Password is required'})
rememberme = forms.BooleanField(required=False)
I get this error message:
ImportError at /
cannot import name rememberMe
view.py I have shortened the view.py here
from django.shortcuts import *
from forms import loginForm, registerForm, verifyForm
from models import UserAccount, SessionLog
import datetime, string, random
from gatherify import settings
from django.core.mail import EmailMessage
def rememberMe(response, user, is_remember):
randomHash = getRandomHash()
if is_remember:
response.set_cookie('kmliCookie', randomHash, settings.COOKIE_LIFETIME)
expiry = datetime.date.today() + datetime.timedelta(seconds=settings.COOKIE_LIFETIME)
else:
response.set_cookie('kmliCookie', randomHash)
expiry = datetime.date.today()
session = SessionLog(secretKey=randomHash, member_id=user.id, date_expiry=expiry)
session.save();
What am i doing wrong here?
Upvotes: 0
Views: 376
Reputation: 599778
You have a circular dependency: forms
imports view
, but view
imports forms
.
You haven't shown the rest of your forms
file, but it is fairly unusual to import views
there. Are you sure you need to?
Upvotes: 2