Python 2.7版
Django版本1.11
尝试使我的第一个Django应用程序保存文档,这里是 models.py
的部分class Docs(models.Model):
FacilityRef = models.ForeignKey(Facility)
Date = models.DateField(default=date.today)
Type = models.CharField(max_length=50)
Link = models.FileField(upload_to='Docs/%Y/%m/%d')
进行迁移时出现以下错误:
Date = models.DateField(default = date.today)NameError:name' date' 未定义
views.py 的一部分:
from django.http import HttpResponse
import datetime
models.py
的一部分 from django.db import models
import datetime
尝试在 views.py 和 models.py 中插入以下字符串,如其中所述 here and here 它没有帮助
from django.utils import timezone
from datetime import datetime
我应该做什么样的导入才能使这个功能起作用?
答案 0 :(得分:3)
<?php
$style= "required";
include('./classes/DB.php');
include('./classes/Login.php');
if (Login::isLoggedIn()) {
echo 'is logged in';
if (isset($_POST['changepassword'])){
$oldpassword = $_POST['oldpassword'];
$newpassword = $_POST['newpassword'];
$newpasswordrepeat = $_POST['newpasswordrepeat'];
$userid = Login::isLoggedIn();
if (password_verify($oldpassword, DB::query('SELECT password FROM users WHERE id=:userid', array(':userid'=>$userid))[0]['password'])) {
if($newpassword == $newpasswordrepeat){
if (strlen($newpassword) >= 6 && strlen($newpassword) <= 60) {
DB::query('UPDATE users SET password =:newpassword WHERE id=:userid', array(':newpassword'=>password_hash($newpassword, PASSWORD_BCRYPT), ':userid'=>$userid));
echo 'password changed succesfuly';
}
}else{
echo 'password don\'t match';
}
}else{
echo 'incorrect old password';
}
}
}
else {
$link= $_SERVER['REQUEST_URI'];
$link_array = explode ('/' ,$link);
$token = end($link_array);
IF(DB::query('SELECT user_id FROM password_tokens where token=:token', array (':token'=>$token))[0]['user_id']){
$user_id = DB::query('SELECT user_id FROM password_tokens where token=:token', array (':token'=>$token))[0]['user_id'];
echo $user_id;
$style= "style= 'display:none'";
if (isset($_POST['changepassword'])){
$newpassword = $_POST['newpassword'];
$newpasswordrepeat = $_POST['newpasswordrepeat'];
if($newpassword == $newpasswordrepeat){
if (strlen($newpassword) >= 6 && strlen($newpassword) <= 60) {
DB::query('UPDATE users SET password =:newpassword WHERE id=:userid', array(':newpassword'=>password_hash($newpassword, PASSWORD_BCRYPT), ':userid'=>$user_id));
}
}else{
echo 'password don\'t match';
}
}
}
else {
die ('token invalid');
}
}
?>
<h1>change your password</h1>
<form action="change_password.php" method="post">
<input type="password" name="oldpassword" value="" placeholder="Current password" <?php echo $style;?>></p>
<input type="password" name="newpassword" value="" placeholder="New password ..." required></p>
<input type="password" name="newpasswordrepeat" value="" placeholder="repeat password ..." required></p>
<input type="button" name="changepassword" value="change password">
</form>
是date
模块的子模块。您永远不会导入名为datetime
的模块,因此当您尝试调用它时会出现NameError。它应该是
date