第一次做项目,记录一下我遇到的坑(泪流满面.jpg),心情感觉就像坐过山车!!!
错误1:Topic不显示Chess和Rock Climbing,而是Topic object(1)和Topic object(2)
解决方法:
注意:def _ _ str_ _(self) 前后有两道下划线!!!
错误2:oduleNotFoundError: No module named ‘django.core.urlresolvers’
解决方法:
将from django.core.urlresolvers import reverse
改为from django.urls import reverse
错误3:models定义class Entry (models.Model):
解决方法:
topic = models.ForeignKey(Topic , on_delete=models.CASCADE)
错误4:learning_logs/urls.py可能出现’Specifying a namespace in include() without providing an app_name ’ django.core.exceptions.
解决方法:
from django.urls import path
from . import views
app_name='learning_logs'
urlpatterns=[
#主页
path('', views.index,name='index'),
#显示所有主题
path('topics/', views.topics, name='topics'),
#特定主题的详细页面
path('topics/(?P<topic_id>\d+)/',views.topic,name='topic'),
path('new_topic/', views.new_topic, name='new_topic'),
path('new_entry/(?P<topic_id>\d+)/)',views.new_entry,name='new_entry'),
path('edit_entry/(?P<entry_id>\d+)/', views.edit_entry,name='edit_entry'),
]
错误5:ModuleNotFoundError: No module named ‘django.core.urlresolvers’
解决方法:
from django.urls import reverse
错误6:TypeError: init() missing 1 required positional argument: ‘on_delete’
解决方法:
将owner = models.ForeignKey(User)
改为owner = models.ForeignKey(User, on_delete=models.CASCADE)
错误7:Cannot run more than 1 Free size dynos.
解决方法:
heroku ps
heroku ps:stop run.5656
heroku ps:stop web.1
错误8:Git bash中运行git log无法退出
解决方法:
按q可以终止运行,对,你没有看错,就是这么简单!!!想当初我太痛苦啦,怎么都退不出来–|||
错误9:在linux终端下快速删除输错
解决方法:
按住esc键同时按backspace键【esc+backspace】,据说【ctrl+u】也可以。
错误10:git push heroku master出错
如下所示:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.heroku.com/ xxxxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决方法:
git push heroku master -ff
有时候超级慢,一直在starting或者connecting,你可以退出重新执行,或者等一会再push。
错误11:在pycharm中使用django可能会有一些问题
解决方法:
最后,感谢度娘,感谢百度后提供帮助的各位大兄弟和小美女,谨以此文纪念自己的第一个小项目