- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在使用此代码来填充我的数据库:
import os
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(name="Django")
add_page(cat=django_cat,
title="Official Django Tutorial",
url="http://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="htttp://www.tangowithdjango.com/")
frame_cat = add_cat(name="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")
# Print out what we have added to the user.
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)
return c
if __name__ == '__main__':
print "Starting Rango population script..."
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'p.settings')
from rango.models import Category, Page
populate()
正在运行
python c:\python27\p\populate_rango.py
它给出了错误:
Staring Rango population script...
Traceback (most recent call last):
File "c:\python27\p\populate_rango.py", line 59, in <module>
populate()
File "c:\python27\p\populate_rango.py", line 4, in populate
python_cat = add_cat('Python')
File "c:\python27\p\populate_rango.py", line 52, in add_cat
c = Category.objects.get_or_create(name=name)
File "C:\Python27\Lib\site-packages\django\db\models\manager.py", li
manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python27\Lib\site-packages\django\db\models\query.py", line
et_or_create
return self.get(**lookup), False
File "C:\Python27\Lib\site-packages\django\db\models\query.py", line
clone = self.filter(*args, **kwargs)
File "C:\Python27\Lib\site-packages\django\db\models\query.py", line
ilter
return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\Lib\site-packages\django\db\models\query.py", line
filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py",
in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py",
in _add_q
current_negated=current_negated, connector=connector)
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py",
in build_filter
lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py",
in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, se
a())
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py",
in names_to_path
field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\Lib\site-packages\django\db\models\options.py", li
get_field_by_name
cache = self.init_name_map()
File "C:\Python27\Lib\site-packages\django\db\models\options.py", li
init_name_map
for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\Lib\site-packages\django\db\models\options.py", li
get_all_related_m2m_objects_with_model
cache = self._fill_related_many_to_many_cache()
File "C:\Python27\Lib\site-packages\django\db\models\options.py", li
_fill_related_many_to_many_cache
for klass in self.apps.get_models():
File "C:\Python27\Lib\site-packages\django\utils\lru_cache.py", line
rapper
result = user_function(*args, **kwds)
File "C:\Python27\Lib\site-packages\django\apps\registry.py", line 1
_models
*self.check_models_ready()
File "C:\Python27\Lib\site-packages\django\apps\registry.py", line 1
ck_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.*
我的其余文件都可以,但出现此错误。我正在学习 Tango with Django 书中的教程,但是因为这本书指的是 Django 1.5.4,而我使用的是 Django 1.8,所以有人可以在这里帮助我吗?
最佳答案
我对 Django 1.7rc2 也有同样的异常(exception)。解决方案是在我的程序开头添加这些行:
import django
django.setup()
关于python - 在 Django 1.8 或更高版本中填充时出现 "Models aren' t 加载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25244631/
我有一个 DIV #page,如果我在顶部添加边距,突然出现一个滚动条,即使该元素不大于主体。我怎样才能去掉滚动条? (参见 Fiddle) 我的 HTML I am a div siz
function getClosestValue(standardArray, targetVal) { standardArray = standardArray.sort(function(a,
我有 318x424 的书籍封面图片,我想做的是指定一张图片,并在其下方添加一个文本链接。初始 src 是 about:blank,这样如果响应式设计不显示框架,它就不会占用用户带宽。 框架的 HTM
我被这个问题困了两天了,还是没搞定。 基本上,我有一个二维数组,其中包含某些数字(在给定范围内)之间的关系: 0 = 顺序无关紧要 1 = 第一个数字(左栏中的数字)应该是第一个 2 = 第二个数字(
只有当我在更高的 API 上进行调试时,我才会强制关闭脚本:16,但是当涉及到 API 时它工作正常:10。这可能是我的项目设置问题吗? 这是对服务器的简单请求,以获取 fragment 中的类别列表
给定下表books id | listorder ----+----------- 3 | 1 2 | 2 1 | 3 4 |
我想要那个密码切换功能,好像TextInputLayout有这个功能,而不是 TextInputEditText .但是正如您在下面的代码中看到的,即使我将高度设置为 wrap_content和 ap
似乎从 读取给出空列表,它主要发生在延迟较高的网络上的主机上。是否有更强大的与远程主机交互的方式? use Net::SSH2; # my $ssh = Net::SSH2->new(); # ..
为了在 Play 商店中发布我的应用程序,我必须将 TargetSdkVersion 从 23 更改为 26。在我更改它之前,该应用程序运行良好!现在应用程序在启动时崩溃。我想通了,问题出在这两行:
我尝试了很多解决方案,但找不到一个。我有 3 个不同的列,其中包含不同类型的文本,我需要它们具有相同的高度。但它们是这样不同的:colums有人可以帮忙吗? 代码: .col-sm-2{
我尝试将一个 div 相对于其具有负顶值的父级定位。这工作正常,现在的问题是这个 div,即使它有一个负的 top 值也会使父 div 更大。 我该怎么做才能让父 div 不那么大? Here's a
这是一个一般性问题,可能适用于任何给定的语言,如 C、C++、Java 等。 我认为无论以何种方式实现它,都不会比使用 2 个循环更高效,后者的效率为 n^2。 for(i=0;i O(1) ),要么
我需要查找所有有订单的家庭。我根本不关心订单的数据,只关心它的存在。 (使用 SQL Server) 这样说是不是更有效率: SELECT HouseholdID, LastName, FirstNa
我有一个 UINavigationController,在屏幕顶部有一个 UINavigationBar,在底部有一个 UIToolbar。我想让工具栏高一点。这是我的代码: CGRect toolb
我正在使用自定义字体。该字体在我的 Windows PC 上完美运行,但在我的 Mac (Yosemite OSX) 上运行不佳。正如您在图片中看到的,Mac 上的字体比 Windows 上的字体稍大
我正在尝试使用 FaSTLane 将我的应用程序作为 alpha 版本部署到 Play 商店,但出现此错误: Google Api 错误:multiApkShadowedActiveApk:任何设备都
我在这里找不到神奇的调味料。看起来 API 不支持它,所以我想我正在寻找一些 CSS 来使 slider 更大。 我得到的是左边的,但我想把它设计成右边的样子?任何 CSS 技巧或以前有人这样做过。
如果我运行这段代码: float a=1.123456789; printf("The float value is %f\n",a); double b=1.123456789876543 prin
我正在尝试使用 strip binary 来剥离我的目标文件。我在 gcc-7 上构建了最新的 binutils,但我的代码库使用 gcc-4.9.2。Binutils 是为 64 位架构构建的,我的
有没有办法让 iPhone 应用的“内容”区域感知到更大的导航栏? 类似这些问题: iOS: Adding a fixed image just below the navigation bar iO
我是一名优秀的程序员,十分优秀!