django 如何调试单独启动文件

想单独启动调试单个py文件,从pycharm启动单独py程序

ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)

ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

求怎么配置settings.

回答:

需要再单独文件的头部上添加

import sys

import os

sys.path.append('/Users/nooper/Documents/work/payment/')

os.environ['DJANGO_SETTINGS_MODULE']="payment.settings"

这里settings就是项目包程序的配置的settings.

需要项目的工作路径引入进来。

回答:

Pycharm debug django问题

报错:
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

  1. 解决:配置一下 run/edit configuration,注意我第二个红色覆盖掉的只setting所在的模块,比如你可能settings是在mysite模块下,那就写mysite.settings
    图片描述

  2. 如果之前已经在terminal里runserver 了,先把他们关掉

  3. 开始debug,出现下面这样的情况就OK了!
    图片描述

  4. 参考http://www.cnblogs.com/lout/articles/4149591.html
    http://stackoverflow.com/questions/27269574/how-to-run-debug-server-for-django-project-in-pycharm-community-edition

以上是 django 如何调试单独启动文件 的全部内容, 来源链接: utcz.com/a/160416.html

回到顶部