我在django 1.4上有一条错误消息:
字典更新序列元素#0的长度为1; 2是必需的
[编辑]
它发生在我尝试使用模板标签时:`{%for v in values%}:
dictionary update sequence element #0 has length 1; 2 is required
Request Method: GET
Request URL: ...
Django Version: 1.4.5
Exception Type: ValueError
Exception Value:
dictionary update sequence element #0 has length 1; 2 is required
Exception Location: /usr/local/lib/python2.7/dist-packages/djorm_hstore/fields.py in __init__, line 21
Python Executable: /usr/bin/uwsgi-core
Python Version: 2.7.3
Python Path:
['/var/www/',
'.',
'',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/pymodules/python2.7']
Server time: sam, 13 Jul 2013 16:15:45 +0200 …Run Code Online (Sandbox Code Playgroud) 我正在开发一个由许多应用程序组成的Django(1.3)项目.每个应用程序在其自己的static目录下都有自己的静态文件.此外,我添加了一个目录project_static,其中应包含静态文件,这些文件在各种应用程序中很常见,例如jQuery.
我立即遇到的问题是命名冲突.默认情况下,collectstatic只需将所有内容放在全局static目录下,而无需按应用程序对其进行分类.这对我不起作用,因为每个应用程序都有 - 例如 - 一个名为的文件css/screen.css.
我的方式解决它是通过消除django.contrib.staticfiles.finders.AppDirectoriesFinder来自STATICFILES_FINDERS和使用命名空间的静态文件显示目录,所以我的设置现在的样子:
STATICFILES_DIRS = (
os.path.join(PROJECT_PATH, 'project_static'),
('my_app', os.path.join(PROJECT_PATH, 'my_app', 'static')),
('another_app', os.path.join(PROJECT_PATH, 'another_app', 'static')),
...
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
)
Run Code Online (Sandbox Code Playgroud)
问题是,通过这种方式,我丢失了所有其他应用程序的静态文件(例如django.contrib.admin).当然我可以手动添加管理员,但我不知道如何在不破坏管理员的情况下执行此操作,管理员具有不同的目录结构.
有没有更好的方法来管理具有多个应用程序的静态文件?
我想我真的搞砸了.在我的django应用程序(生产一个)上,我推了一个重大更新,每当我尝试进入我的域时就会出现"内部服务器错误".我在uwsgi日志中收到错误:
*** Starting uWSGI 2.0.8 (64bit) on [Thu Jan 29 00:36:43 2015] ***
compiled with version: 4.8.2 on 11 December 2014 17:29:38
os: Linux-3.13.0-41-generic #70-Ubuntu SMP Tue Nov 25 14:40:34 UTC 2014
nodename: ip-172-31-9-208
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root …Run Code Online (Sandbox Code Playgroud) 在阅读了许多文档AsyncIO和文章后,我仍然找不到答案:异步运行函数(不使用线程)并确保调用此异步函数的函数继续执行。
伪代码:
async def functionAsync(p):
#...
#perform intensive calculations
#...
print ("Async loop done")
def functionNormal():
p = ""
functionAsync(p)
return ("Main loop ended")
print ("Start Code")
print functionNormal()
Run Code Online (Sandbox Code Playgroud)
预期输出:
Start code
Main loop ended
Async loop done
Run Code Online (Sandbox Code Playgroud)
搜索使用的示例loop.run_until_complete,但不会返回 的打印值,functionNormal()因为它本质上是阻塞的。
我在Django项目中使用Grunt管理所有静态文件。我为我的项目设置了一个gruntfile文件,该文件获取所有js和css文件,然后合并并缩小到一个文件中。这些文件被复制到一个名为的目录/static/source,在我的设置中,我已经配置了静态文件,如下所示:
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static/build'),
)
STATIC_ROOT = os.path.join(PUBLIC_ROOT, 'static')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
)
Run Code Online (Sandbox Code Playgroud)
所有这些工作正常,我对此没有任何问题。问题是当我尝试使用该admin应用程序时。如果我加入STATICFILES_FINDERS了django.contrib.staticfiles.finders.AppDirectoriesFinder,当我做collectatic过程中,它也将所有静态文件从我的应用程序(我已经连接起来,并与咕噜精缩源文件)。
有什么方法可以只为某个应用程序收集静态文件吗?
环境: 在Windows 10主机上的Vagrant / Virtualbox中运行的Ubuntu 16.04(系统Python在2.7.12)
Python安装程序: 通过执行python -V验证了系统python,未激活virtualenv。还安装了Python 3.5,并且已经pipenv --three为该项目创建了virtualenv。在激活的virtualenv中进行python -V(pipenv shell激活)显示Python 3.5.2。
其他背景: 我正在开发Wagtail 2应用程序。Wagtail 2需要Django 2,而它当然需要Python3。我在这台机器上还有其他Django应用程序,这些应用程序是Django 1.11 / Python 2.7开发的,由Apache提供。我们将继续使用Django 2 / Python 3进行开发,并正在使用nginx / uWSGI来提供应用程序。
我经历了许多教程/许多迭代。所有的Vagrant端口映射都可以通过nginx提供媒体/静态文件并在Unix套接字上向Django应用传递请求到Django应用的设置很好地设置,但这会导致502 Gateway not found错误,因为uWSGI无法正确运行。因此,现在我只是在命令行中运行以下命令,以尝试运行uWSGI : uwsgi --ini /etc/uwsgi/sites/my_site.com.ini。该文件包含:
[uwsgi]
uid = www-data
gid = www-data
plugin = python35
# Django-related settings
# the base directory (full path)
chdir=/var/sites/my_site
# Django's wsgi file
wsgi-file = my_site.wsgi
# the virtualenv (full path)
virtualenv=/root/.local/share/virtualenvs/my_site-gmmiTMID
# process-related settings
# master …Run Code Online (Sandbox Code Playgroud) 当没有值时,是否有一种在管理中显示默认值的djangtastic方法?像'不适用',但不是要保存到数据库?
当我将下面模型中的所有字段设置为只在管理员中读取时,前端显示看起来像底部的图像.它看起来像是应该有一个价值或一个盒子或东西.如果没有一种简单的方法来完成我正在寻找的东西,那么还有另一种解决方案可以让前端管理员更清楚地为用户服务吗?
class Package(models.Model):
packaging_format = models.CharField(max_length=40)
package_delivery_pattern = models.CharField(max_length=30, blank=True)
package_delivery_comments = models.CharField(max_length=250, blank=True)
package_manifest_filename = models.CharField(max_length=50)
package_description = models.CharField(max_length=250, blank=True)
package_naming_pattern = models.CharField(max_length=50)
Run Code Online (Sandbox Code Playgroud)
显示管理员的字段截图:

我使用 Wagtail 的表单生成器创建了一个表单,其中包含多行文本项。当<textarea>元素被渲染时,它会使用 进行渲染rows="10"。我需要减少行数,但在文档中没有看到有关如何执行此操作的任何内容。
我在cypress / support / commands.js文件中创建了以下自定义命令。
Cypress.Commands.add("login", (username, password) => {
cy.request({
method: 'POST',
form: true,
url: '/test/login/',
body: {'username': username, 'password': password}
})
})
Run Code Online (Sandbox Code Playgroud)
在将登录功能移至此自定义命令之前,我已经通过了测试并进行了登录工作。我正在使用cy.login(testuser,testpwd)在我的规范中调用它,但是我收到以下错误消息:TypeError:cy.login不是函数。该文件说任何测试文件进行评估之前/cypress/support/commands.js被加载,所以我认为简单地将一个自定义命令在那里会使命令可用。我正在通过本地(GUI)测试运行程序运行测试。
在我的信用卡结帐表格中,我有以下内容:
$('#checkout-info')
.form({
on : 'blur',
fields : {
id_cc_num : { identifier: 'id_cc_num',
optional: true,
rules: []},
id_cc_CVC : { identifier: 'id_cc_CVC',
optional: true,
rules: [{ type: 'regExp[/\d{3,4}/]',
prompt: 'CVC must be three or four digits'}]},
id_cc_month : { identifier: 'id_cc_month',
optional: true,
rules: [{ type: 'integer[1..12]',
prompt: 'MM must be a two-digit month designator - 01 thru 12'}]},
id_cc_year : { identifier: 'id_cc_year',
optional: true,
rules: [{ type: 'integer[2016..2036]',
prompt: 'Year must be at least 2016'}]},
inline : …Run Code Online (Sandbox Code Playgroud) 尝试减去两个不同的列时,出现此错误:
>>> Product.objects.annotate(Sum('producttransactiondetails__purchase_quantity') - Sum('producttransactiondetails__sales_quantity'))
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
File "/home/....env/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/.....env/lib/python3.6/site-packages/django/db/models/query.py", line 1032, in annotate
if arg.default_alias in kwargs:
AttributeError: 'CombinedExpression' object has no attribute 'default_alias'
Run Code Online (Sandbox Code Playgroud)
以下是模型:
class ProductTransactionDetails(models.Model):
product = models.ForeignKey(Product, on_delete=models.PROTECT)
product_purchase = models.ForeignKey(ProductTransaction, on_delete=models.PROTECT)
purchase_quantity = models.PositiveIntegerField(default=0)
sales_quantity = models.PositiveIntegerField(default=0)
discount = models.DecimalField(max_digits=20, decimal_places=2)
product_price = models.DecimalField(max_digits=20, decimal_places=2)
created_at = models.DateTimeField(auto_now_add=True)
updated_at …Run Code Online (Sandbox Code Playgroud) django ×7
python ×4
uwsgi ×3
asynchronous ×1
cypress ×1
django-admin ×1
gruntjs ×1
javascript ×1
nginx ×1
python-3.x ×1
regex ×1
semantic-ui ×1
validation ×1
wagtail ×1