我有这些模型:
def Foo(Models.model):
size = models.IntegerField()
# other fields
def is_active(self):
if check_condition:
return True
else:
return False
def Bar(Models.model):
foo = models.ForeignKey("Foo")
# other fields
Run Code Online (Sandbox Code Playgroud)
现在我想要查询具有活动Foo的条形码:
Bar.objects.filter(foo.is_active())
Run Code Online (Sandbox Code Playgroud)
我收到的错误如
SyntaxError at /
('non-keyword arg after keyword arg'
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个奇怪的问题,我想使用上下文处理器添加一个全局查询.这就是我通过以下方式做到的:
在我的应用程序中制作了processor.py:
from myproject.myapp.models import Foo
def foos(request):
return {'foos': Foo.objects.all()}
Run Code Online (Sandbox Code Playgroud)
在我的setting.py结束时我添加了这个:
TEMPLATE_CONTEXT_PROCESSORS = ('myapp.processor.foos',)
Run Code Online (Sandbox Code Playgroud)
最后我传递了我的观点:
def index_view(request):
return render_to_response('index.html', {}, context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
在我的index.html模板:
<select id="select_foo">
{% for foo in foos %}
<option value="/{{ foo.slug }}">{{ foo.name }}</option>
{% endfor %}
</select>
Run Code Online (Sandbox Code Playgroud)
最后我的网址:
(r'^$', 'myapp.views.index_view'),
Run Code Online (Sandbox Code Playgroud)
我的foos显示没有任何问题,但我的media_url和其他上下文已经消失.可能是什么问题
我想举办它使用Debian的5同一服务器下的几个场所,说我有site1,site2和site3,并承担我的IP是155.55.55.1:
site1: 155.55.55.1:80 , script at /opt/django/site1/
site2: 155.55.55.1:8080, script at /opt/django/site2/
site3: 155.55.55.1:8090, script at /opt/django/site3/
Run Code Online (Sandbox Code Playgroud)
这是我的apache默认值:
<VirtualHost *:80>
ServerName /
ServerAlias */
DocumentRoot /opt/django/site1/
LogLevel warn
WSGIScriptAlias / /opt/django/site1/apache/django.wsgi
Alias /media /opt/django/site1/media/statics
Alias /admin_media /home/myuser/Django-1.1/django/contrib/admin/media
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/usr/share/phpmyadmin"
ServerName /phpmyadmin
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
这是我的wsgi配置site1,在/opt/django/site1/apache/django.wsgi:
import os, sys
import django.core.handlers.wsgi
sys.path.append('/opt/django') …Run Code Online (Sandbox Code Playgroud) 如何在django模板系统中分配变量?
假设Restaurant是一个模型:
{% restaurant_id as restaurant.id %}或者{{ restaurant_id as restaurant.id }}不工作.
这是我想要的内容BACKUPDIR,我想要执行,cscript /nologo c:\deletefile.vbs %BACKUPDIR%直到文件夹内的文件数大于21(countfiles保留它).这是我的代码:
@echo off
SET BACKUPDIR=C:\test
for /f %%x in ('dir %BACKUPDIR% /b ^| find /v /c "::"') do set countfiles=%%x
for %countfiles% GTR 21 (
cscript /nologo c:\deletefile.vbs %BACKUPDIR%
set /a countfiles-=%countfiles%
)
Run Code Online (Sandbox Code Playgroud) 如何使用Psycopg2 Python库确定表是否存在?我想要一个真或假的布尔值.
我很好奇什么是独特的这种数据对象的有效方式:
testdata =[ ['9034968', 'ETH'], ['14160113', 'ETH'], ['9034968', 'ETH'], ['11111', 'NOT'], ['9555269', 'NOT'], ['15724032', 'ETH'], ['15481740', 'ETH'], ['15481757', 'ETH'], ['15481724', 'ETH'], ['10307528', 'ETH'], ['15481757', 'ETH'], ['15481724', 'ETH'], ['15481740', 'ETH'], ['15379365', 'ETH'], ['11111', 'NOT'], ['9555269', 'NOT'], ['15379365', 'ETH']
]
Run Code Online (Sandbox Code Playgroud)
对于每一个数据对,左侧的数字串PLUS在合适的类型告知的数据元素的唯一性.它返回与testdata相同的列表列表,但只存在唯一身份证.
问候
我很好奇是否存在通过使用一些权重计算,出现率或其他工具从给定文本生成关键字/标签的算法/方法.
另外,如果您为此指出任何基于Python的解决方案/库,我将不胜感激.
谢谢
我怎样才能完成这样的工作:
def get_foo(someobject, foostring):
return someobject.foostring
Run Code Online (Sandbox Code Playgroud)
IE:
如果我这样做get_foo(obj, "name")应该是调用obj.name(请参阅输入字符串,但我称之为attritube.
谢谢
python ×8
django ×4
apache2 ×1
attributes ×1
batch-file ×1
django-orm ×1
for-loop ×1
hosting ×1
http ×1
http-head ×1
httprequest ×1
mod-wsgi ×1
nlp ×1
nltk ×1
postgresql ×1
psycopg2 ×1
scripting ×1
tags ×1
unique ×1
while-loop ×1
windows ×1