在程序中要添加django.setup()

整个程序如下所示

import os
import django def populate():
python_cat = add_cat('Python') add_page(cat=python_cat,
title="Official Python Tutorial",
url="http://docs.python.org/2/tutorial/") add_page(cat=python_cat,
title="How to Think like a Computer Scientist",
url="http://www.greenteapress.com/thinkpython/") add_page(cat=python_cat,
title="Learn Python in 10 Minutes",
url="http://www.korokithakis.net/tutorials/python/") django_cat = add_cat("Django") add_page(cat=django_cat,
title="Official Django Tutorial",
url="https://docs.djangoproject.com/en/1.5/intro/tutorial01/") add_page(cat=django_cat,
title="Django Rocks",
url="http://www.djangorocks.com/") add_page(cat=django_cat,
title="How to Tango with Django",
url="http://www.tangowithdjango.com/") frame_cat = add_cat("Other Frameworks") add_page(cat=frame_cat,
title="Bottle",
url="http://bottlepy.org/docs/dev/") add_page(cat=frame_cat,
title="Flask",
url="http://flask.pocoo.org") for c in Category.objects.all():
for p in Page.objects.filter(category = c):
print "- {0} - {1}".format(str(c),str(p)) def add_page(cat,title, url, views = 0):
p = Page.objects.get_or_create(category = cat, title = title, url = url, views = views)[0]
return p; def add_cat(name):
c = Category.objects.get_or_create(name = name)[0]
return c if __name__ == '__main__':
print "Starting rango population script..."
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoHelloworld.settings");
django.setup() #添加的代码
from HelloWorld.models import Category,Page
populate()

Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet的更多相关文章

  1. django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.的解决办法

    如题,这个错误的解决办法如下: 在代码文件的最上方添加以下代码: import os,django os.environ.setdefault("DJANGO_SETTINGS_MODULE ...

  2. django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

    报错现象 django 启动的时候报错 django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. 报错解决 记不清是我有毛 ...

  3. pycharm运行Django发生AppRegistryNotReady: Apps aren't loaded yet.

    pycharm中运行django默认情况下并不是执行项目的,所以如果在非manage.py,会发生异常. raise AppRegistryNotReady("Apps aren't loa ...

  4. Django 资源 与 知识 Django中自建脚本并使用Django环境 model中的save()方法说明 filter()用法

    Django 资源 与 知识 Django中自建脚本并使用Django环境 model中的save()方法说明 filter()用法 2018/11/06 Chenxin 资料说明 Django基础入 ...

  5. python基于Django框架编译报错“django.core.exceptions.ImproperlyConfigured”的解决办法?

    下面是我具体遇到的问题和解决方法: 错误详细信息: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_IND ...

  6. pythoncharm 中解决启动server时出现 “django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured”的错误

    背景介绍 最近,尝试着用pythoncharm 这个All-star IDE来搞一搞Django,于是乎,下载专业版,PJ等等一系列操作之后,终于得偿所愿.可以开工了. 错误 在园子里找了一篇初学者的 ...

  7. 关于Django报错django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configure

    报错代码:django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but se ...

  8. django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. Did you install mysqlclient or MySQL-python?

    Error msg: Unhandled exception in thread started by <function check_errors.<locals>.wrapper ...

  9. 【Django】django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.

    最近学习Django的过程中,在cmd打算使用python manage.py shell来测试数据的时候,当我一导入自己写的model类,就发现报了这个错误django.core.exception ...

随机推荐

  1. JS 初级 二(接上)

    传送门--http://www.cnblogs.com/Sabo-dudu/p/5786683.html (一) 六. JS 数组类型 数组是一种保存数据的有序列表,数组的每一项可以保存人意类型的数据 ...

  2. 在_vimrc中 set noexpandtab python 不起效果

    我ctm,今天配置不让tab转为空格,在_vimrc中set noexpandtab 不起效果. set ts=4也不起效果. 但是在命令行中其效果. 我都不知道咋办了. 问人说我有可能使用的不是那个 ...

  3. Java实现比较版本号

    涉及到客户端的系统中经常需要用到比较版本号的功能,但是比较版本号又不能完全按照字符串比较的方式去用compareTo之类的方法: 这就需要我们总结版本号的通用规则,设计一个比较算法并封装成通用方法来使 ...

  4. ListView加载性能优化---ViewHolder---分页

    ListView是Android中一个重要的组件,可以使用它加列表数据,用户可以自己定义列表数据,同时ListView的数据加载要借助Adapter,一般情况下要在Adapter类中重写getCoun ...

  5. wget 断点续传 & nginx文件服务器

    nginx默认支持断点续传: 测试方法: wget -S http://httpd.apache.org/images/httpd_logo_wide_new.png 2>&1 | gr ...

  6. Unity3D 接完GVR SDk后如何插入自己的java代码

    1.用Eclipse创建一个Android Application Project 2.用压缩软件打开gvr_android_common.aar和unitygvractivity.aar,分别把里面 ...

  7. linux c/c++

    string 字符串操作 操作数的都是 ( char * )型,操作数必须是指向字符串的指针("a"),不能是字符('a'),操作时不考虑末尾的'\0'. size_t strle ...

  8. STM32 IIC

    #include "Type.h" #include "IIC.h" #include "Delay.h" void I2C_Init(vo ...

  9. navicat 破解

    首先上官网上下载LINUX版本: http://www.navicat.com/download 下载 navicat110_mysql_en.tar.gz 文件 下载后解压tar文件 tar -zx ...

  10. Java常用的技术网站

    学习Java,我会去的网站: 1.开源项目网站:https://github.com/和http://www.codeproject.com/,可以在这里搜索到别人上传的一些代码和项目 2.咨询问题的 ...