尽管模块存在,但在尝试将视图中的模块“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();
我在这里做错了什么?