1.运行pycharm程序,一直提醒配置错误,但实际上有重新导入python.py模块。强制运行代码,提示以下内容:error running ‘main_redis’ @NotNull method com/intellij/execution/configurations/generalCommandLine.getExePath must not return null
解决办法:重新配置python解释器
2.已经安装了PyMySQL,但是还是提示错误
解决办法:重新配置python解释器
3.ModuleNotFoundError: No module named ‘runpy’
django虚拟环境出问题了,我的解决办法是重新搭建环境,可以参考我的博客django基础(1).
4.home() takes 0 positional arguments but 1 was given
解决办法:函数Home缺少一个参数request
5.The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
解决办法:删除STATIC_ROOT = os.path.join(BASE_DIR,’static’)
6.Reverse for ‘user_market’ not found. ‘user_market’ is not a valid view function or pattern name.
修改:<a href="{% url 'app:user_market' %}" class="market">
为:
<a href="{% url 'app:market' %}" class="market">
7.python3 查看解释器和包安装路径
import sys
print (sys.path)
8.安装了Anaconda3导致一直找不到python解释器
我的解决办法:重新安全python
9.reverse() got an unexpected keyword argument ‘params’
args错误的写成params
10.Cannot resolve keyword ‘ticket’ into field. Choices are: cartmodel, email, icon, id, is_delete, ordermodel, password, sex, username, userticketmodel
user_ticket = UserModel.objects.filter(ticket=ticket).first(),模块引入错误,应该从UserTicketModel 模块引入ticket
11.ype object ‘FoodType’ has no attribute ‘filter’
foodtypes = FoodType.filter.all()
12.QuerySet’ object has no attribute ‘objects’
current_foodtypes = foodtypes.objects.filter(typeid=typeid).first()
改为:
current_foodtypes = foodtypes.filter(typeid=typeid).first()
13.{% csrf_token %}
原因是django为了在用户提交表单时防止跨站攻击所做的保护 ,这是Django提供的防止伪装提交请求的功能。POST 方法提交的表格,必须有此标签。
14.Django出现报错’AnonymousUser’ object is not iterable
在报错的 View 函数中 的对应 逻辑前 加上:
if request.user.is_authenticated():
执行语句
15.local variable ‘user_carts’ referenced before assignment
原先代码:
if request.user.is_authenticated():
user_carts = CartModel.objects.filter(user=user)
data = {
'user_carts': user_carts
}
修改之后:理由是if没有执行的情况,user_cart的初始值为空
user_cart = ''
if request.user.is_authenticated():
user_carts = CartModel.objects.filter(user=user)
data = {
'user_carts': user_carts
}
16.ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- 停止mysql服务
systemctl stop mysqld.service
修改配置文件无密码登录
vi /etc/my.cnf
在最尾部加上:skip-grant-tables ,保存
启动mysql
systemctl start mysqld.service
登录mysql,mysql -u root .此处注意不要加-p
修改密码,mysql5.7用此语法
use mysql ;
update mysql.user set authentication_string=password(‘123456’) where user=’root’ ;
回到第二步骤去掉加上的
- skip-grant-tables
保存 重启mysql就ok了
PS:以上具体解决办法参考地址:https://blog.csdn.net/keepd/article/details/77151006
17.连接阿里云服务器的数据库,用户密码都正确,但是一直连接不上
解决办法:开启阿里云服务器3306端口,将其添加到安全规则中
具体解决方案:https://jingyan.baidu.com/article/03b2f78c31bdea5ea237ae88.html
18.round() 方法返回浮点数x的四舍五入值。
data = {
#精确到小数点后3位
'count_price': round(price, 3)
}
19.Cannot assign “
if request.user.is_authenticated():
# Do something for logged-in users.
else:
# Do something for anonymous users
报错出现AnonymousUser,一般都是用户没有登录,需要添加以上代码即可.
参考:http://www.runoob.com/django/django-form.html
20.TypeError: reverse() takes exactly 2 arguments (1 given)
response = HttpResponseRedirect(reverse('app:mine'))
修改为:
response = render(request,'mine/mine.html')
以上问题是我在做项目过程遇到的问题,现在看来都觉得很简单啊,只是遇到的时候还是花了一些时间去解决.都说编程就是要不断踩坑,踩的坑多了就成了大神.哈哈,看来我正在通往大神的道路越走越远啊!不过还有很多的坑等着我去踩,以后学习过程会不断总结的.总结让我思维更加连贯!