无法将现有模块导入Django中的表单

时间:2013-10-21 18:25:23

标签: python django

我尝试将模块“rememberMe”导入forms.py时遇到奇怪的导入错误,尽管模块存在。 (shell中的相同import语句工作正常)。

 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)

我收到此错误消息:

ImportError at /
cannot import name rememberMe

view.py我在这里缩短了view.py

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();

我在这里做错了什么?

1 个答案:

答案 0 :(得分:2)

您有循环依赖:forms导入view,但view导入forms

您尚未显示forms文件的其余部分,但在那里导入views是相当不寻常的。你确定需要吗?