我想在同一个for循环中遍历django模板中的多个列表.我该怎么做?
一些思考链接:
{% for item1, item2, item3 in list1, list2 list3 %}
{{ item1 }}, {{ item2 }}, {{ item3 }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
这样的事情可能吗?
我似乎无法在隐藏字段上显示来自jQuery UI的日期选择器,因为我收到此错误:
Uncaught TypeError: Cannot read property 'left' of undefined
Run Code Online (Sandbox Code Playgroud)
当我使用常规文本字段时,我似乎没有问题.我得到这个错误既jQuery UI 1.9.0和1.9.2,版本jQuery is 1.8.3
HTML
<table>
<tr>
<td>
<small class="date_target">until <span>Dec. 31, 2013</span></small>
<input type="hidden" class="end_date" />
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
JS
$(".end_date").datepicker({
dateFormat: 'yyyy-mm-yy',
yearRange: '-00:+01'
});
$('.date_target').click(function () {
$(this).next().datepicker('show');
});
Run Code Online (Sandbox Code Playgroud)
我在此提供了一个(不)工作示例的jsfiddle太
为noobish问题道歉,我对Python和Django都是全新的,并试图制作我的第一个应用程序.
我有一个简单的课程
class About(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
date = models.DateTimeField('date added')
Run Code Online (Sandbox Code Playgroud)
我添加了一条记录.我可以访问它
about = About.objects.filter(id=1)
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试使用点语法来访问其属性,我会收到以下错误
>>> about.title
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'title'
Run Code Online (Sandbox Code Playgroud)
我知道如何在模型中使用unicode来指定更好的返回值,例如
def __unicode__(self):
return self.title
Run Code Online (Sandbox Code Playgroud)
我应该使用它来将模型数据格式化为字典/列表吗?或者我只是完全错过了一些默认行为?
我正在尝试将 Django 密钥设置为我的venv/bin/activate.
但密钥中有一个“(”,我收到 venv 错误-bash: venv/bin/activate: line 85: syntax error near unexpected token ')'
我有点卡在这里。如何将此键设置为本地环境变量,以便它接受这些特殊字符?
正如标题所提到的,在 Django 中:
假设我有一个模型名称 QuestionRecord,有两个字段:full_score和actual_score。我想实现的SQL:
select * from QuestionRecord as QR where QR.full_score!=QR.actual_score.
Run Code Online (Sandbox Code Playgroud)
也许使用原始 sql 是可以的,但我想像这样实现它:
class QuestionRecord_QuerySet(models.query.QuerySet):
def incorrect(self):# Find out those whose full_score and actual_score are not equal
return self.filter(...) # **What should I write here??**
class QuestionRecord_Manager(models.Manager):
def get_query_set(self):
return QuestionRecord_QuerySet(self.model)
class QuestionRecord(models.Model):
objects = QuestionRecord_Manager()
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?
我正在使用django-nose在django(1.4)中运行我的单元测试.
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
Run Code Online (Sandbox Code Playgroud)
创建数据库需要很长时间.
所以我发现把它放在settings.py中:
os.environ['REUSE_DB'] = "1"
Run Code Online (Sandbox Code Playgroud)
应该做的伎俩.
实际上django itsellve给出了这个建议:
To reuse old database "<path not very interesting>/var/sqlite/unittest.db" for speed, set env var REUSE_DB=1.
Run Code Online (Sandbox Code Playgroud)
当然,您需要使用此标志= 0运行一次(或在每次数据库更改后)
但是,当您将标志设置为0时,我的测试以注释结束:
Destroying test database for alias 'default'...
Run Code Online (Sandbox Code Playgroud)
因此,当我想重复运行它时......没有什么可以重用...而且我会得到错误,表示该表不存在
DatabaseError: no such table: <and than a table name>
Run Code Online (Sandbox Code Playgroud)
将reuse_db设置为0时,测试运行完美
我在我的开发设置中使用测试数据库别名:
DATABASES = {
'default': {
'NAME': os.path.join(BUILDOUT_DIR, 'var', 'sqlite', 'development.db'),
'TEST_NAME': os.path.join(BUILDOUT_DIR, 'var', 'sqlite', 'unittest.db'),
'ENGINE': 'django.db.backends.sqlite3',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
Run Code Online (Sandbox Code Playgroud)
我没有使用内存中的sqllite数据库进行测试,因为我读到某个地方这对django-nose不起作用.
那么如何在最终销毁数据库时重用数据库...
根据这个https://docs.djangoproject.com/en/1.4/topics/testing/#the-test-database django这样做,但它没有显示如何防止这种情况(如果我可以),或者如何使用reuse_db选项.我应该使用其他设置吗?
龙卷风支持Content-Type "application/json"吗?
根据调用堆栈(假设stream_request_body = False),调用请求体的唯一方法是parse_body_arguments(httputil.py 662),它只接受"application/x-www-form-urlencoded"和"multipart/form-data"
我重构了一个已经部署(并且运行良好)的 Django 项目,以使用设置目录而不是 settings.py 文件。项目结构如下图:
project/
app1/
app2/
project/
settings/
__init__.py
base.py
production.py
Run Code Online (Sandbox Code Playgroud)
服务器已停止工作。我收到 502 错误。我相信这是因为gunicorn 找不到设置文件了。我尝试更改我的 wsgi 文件以使用生产而不是设置。
wsgi.py
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.production")
Run Code Online (Sandbox Code Playgroud)
生产.py
from .base import *
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = ["site.com", "ip"]
Run Code Online (Sandbox Code Playgroud)
base.py对于一些静态和媒体路由来说几乎是默认的。
问题:
我如何告诉gunicorn我的新文件夹结构,以便它知道要运行的正确设置文件。
编辑:
暴发户错误:gunicorn: Worker failed to boot.
第二个错误:Import Error: No module named project.wsgi
我想做以下事情:我想定义一个递归函数,funct在该函数中,它自己的最后一个引用返回数组的一个数字temp。问题是funct必须对自身进行积分(请参阅下面的代码),如果funct可以接受冒号:作为参数,这将非常容易。所以,到目前为止我有这个(简化的)代码:
import numpy as np
import scipy.integrate as ints
temp = np.array([[1,2,3,4,5],[4,0,6,7,8],[7,8,9,10,11],[1,2,3,4,5],[6,7,8,9,10]])
def funct(x,y,n):
if n>1:
return (temp[x,y] + ints.cumtrapz(temp[x,:]*funct(:,y,n-1), x=None, dx=1, initial=0)[-1])
else:
return temp[x,y]
funct = np.vectorize(funct)
funct(1,1,3)
Run Code Online (Sandbox Code Playgroud)
问题是,funct不能接受结肠:作为参数,它并不重要,如果我想矢量化到funct后面的代码。
例如,如果我更改上述代码的这一部分
ints.cumtrapz(temp[x,:]*funct(:,y,n-1), x=None, dx=1, initial=0)[-1])
Run Code Online (Sandbox Code Playgroud)
为了
ints.cumtrapz(temp[x,:]*temp[:,y], x=None, dx=1, initial=0)[-1])
Run Code Online (Sandbox Code Playgroud)
我没有问题。我只想递归地做最后一部分。
所以我在球拍中编写了I函数来计算Sums:
(define (sum term a next b)
(if (> a b)
0
(+ (term a) (sum term (next a) next b))))
Run Code Online (Sandbox Code Playgroud)
术语是应用于每个参数的函数.A接下来是我们如何前进到下一个元素(即a2 = 2*a1或a2 = a1 + 1等),b是最后一个元素.
还有2个附加功能:
(define (square x) (* x x))
(define (inc x) (+ x 1))
Run Code Online (Sandbox Code Playgroud)
如果我输入:
(sum square 1 inc 5)我得到的是正确的55
但如果我输入:
(总平方1平方5)
我陷入了困境!?为什么a2应该是a1*a1和a3 = a2*a2并且a应该超过b,因此结束递归的条件将是fultifield.很奇怪.
在内部管理员我想要list_display一个模型包括get_absolute_url和可点击.目前它只是显示/x/(x是ID).任何快速修复?
模型:
def get_absolute_url(self):
return "/%i/" % self.id
Run Code Online (Sandbox Code Playgroud)
管理员:
list_display = ('name', 'get_absolute_url')
Run Code Online (Sandbox Code Playgroud) 在尝试安装Rails 3时,我收到以下错误:
命令运行: sudo gem install rails --pre
错误现在:
Successfully installed rails-3.0.0.rc2
1 gem installed
Installing ri documentation for rails-3.0.0.rc2...
File not found: lib
Run Code Online (Sandbox Code Playgroud) django ×7
python ×5
arguments ×1
colon ×1
django-admin ×1
django-nose ×1
function ×1
gunicorn ×1
heroku ×1
jquery-ui ×1
json ×1
lisp ×1
list ×1
nginx ×1
racket ×1
recurrence ×1
scheme ×1
tornado ×1
unit-testing ×1
virtualenv ×1