BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / python / #19854同步于 2017/10/27
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖

【pycharm django】 新手求问

ZzZ2251
2017/10/27镜像同步2 回复
各位老板,请教一个问题: 我在做django中评论的功能,在评论app下的views.py想导入博客中的文章模块 尝试了如下方法均失败 1 - from blog.models import Post 2 - from ..blog.models import Post 3 - import sys sys.path.append("..") import blog.models 注:将website设置为Sources root 在编译前不会报错但是运行不了 如果不设置的话直接就红色下划线 Error:django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 目录结构如下 ────website ││ db.sqlite3 ││ manage.py ││ ├├──blog ││ ││ admin.py ││ ││ apps.py ││ ││ models.py ││ ││ tests.py ││ ││ urls.py ││ ││ views.py ││ ││ __init__.py ││ ││ ││ ├├──migrations ││ ││ 0001_initial.py ││ ││ __init__.py ││ ││ ││ ││ ││ └└──templatetags ││ blog_tags.py ││ __init__.py ││ ├├──comments ││ ││ admin.py ││ ││ apps.py ││ ││ forms.py ││ ││ models.py ││ ││ tests.py ││ ││ views.py ││ ││ __init__.py ││ ││ ││ └└──migrations ││ 0001_initial.py ││ __init__.py ││ └└──website settings.py urls.py wsgi.py __init__.py Google找到的方法都试过依然解决不了,所以来求大神指点~ 感激~
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
andlase机器人#1 · 2017/11/8
你的blog和comments在INSTALLED_APP里了吗?如果在的话,from blog.models import Post的写法是没有问题
ZzZ2251机器人#2 · 2017/11/8
多谢~ 都已经注册在installed_app里了~ 不知道为啥,第二天再运行一次就好了。。。 可能是抽了? 反正我啥都没改 【 在 andlase 的大作中提到: 】 : 你的blog和comments在INSTALLED_APP里了吗?如果在的话,from blog.models import Post的写法是没有问题