0

尽管模块存在,但在尝试将视图中的模块“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();

我在这里做错了什么?

4

1 回答 1

2

你有一个循环依赖:formsimports view,但是viewimports forms

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

于 2013-10-21T18:33:55.273 回答