我们正在使用 Apache、Python 和 Django 开发一个新网站。
在开发阶段,没问题,但是一旦绑定到Apache,使用Firefox 3.5.3,我们遇到了一个奇怪的问题。
我们坚持:
当我们想改变研究的顺序时,我们将用户发送到:
http://website.fr/search/order/price/
此页面更改会话变量并使用代码 302 重定向到:
问题是 Apache 发送了 302 Apache 代码,而 Firefox 不刷新页面。当我们将用户重定向到他之前所在的页面时,我们遇到了同样的问题。
我们应该怎么做才能强制刷新页面?
我的问题是if条件.
我想这样的事情,但无法弄清楚如何做到这一点.
{% if restaurant.is_favorite_of(user) %}
<img src="{{MEDIA_URL}}images/favorite_on.png" alt="This restaurant is one of your favorite (Click to undo)" />
{% else %}
<img src="{{MEDIA_URL}}images/favorite_off.png" alt="This restaurant is not one of your favorite (Click to add to your favorite)" />
{% endif %}
Run Code Online (Sandbox Code Playgroud)
在收藏夹经理中,我创建了:
def is_favorite(self, user, content_object):
"""
This method returns :
- True if content_object is favorite of user
- False if not
>>> user = User.objects.get(username="alice")
>>> fav_user = User.objects.get(username="bob")
>>> fav1 = Favorite.create_favorite(user, fav_user)
>>> Favorite.objects.is_favorite(user, fav_user) …Run Code Online (Sandbox Code Playgroud) 在我正在做的webapp中,我需要识别人们在说话的语言.我想用旗帜来做那件事.但我有一些问题.
例如,如果你说法语,你可以把法国国旗.但如果你说英语,你可以把美国或英国的旗帜或两者兼而有之.
为阿拉伯语选择哪个标志?沙特阿拉伯国旗?阿尔及利亚?摩洛哥?
我正在尝试使用不应修改的文件来创建模型.但该文件的评论可以.
这是我做的,但我们无法修改评论.如何测试是否已发送新文件(使用浏览按钮),仅在此情况下,创建模型的新实例?如果没有上传新文件,请更新评论.
admin.py
class CGUAdminForm(forms.ModelForm):
class Meta:
model = ConditionsUtilisation
def clean_file(self):
if self.instance and self.instance.pk is not None:
raise forms.ValidationError(_(u'You cannot modify the file. Thank you to create a new instance.'))
# do something that validates your data
return self.cleaned_data["file"]
class CGUAdmin(admin.ModelAdmin):
form = CGUAdminForm
admin.site.register(ConditionsUtilisation, CGUAdmin)
Run Code Online (Sandbox Code Playgroud)
models.py
class ConditionsUtilisation(models.Model):
date = models.DateField(_(u'Date d\'upload'), editable=False, auto_now_add=True)
comment = models.TextField(_(u'Commentaire de modification'))
file = models.FileField(_(u'CGU'), upload_to='subscription/cgu/', storage=CGUFileSystemStorage())
Run Code Online (Sandbox Code Playgroud) 我正在尝试将值转换为标准值的PhoneField.
在这种情况下,我想使用这种干净的方法.
def clean(self):
phone = self.cleaned_data.get('phone')
# Is it already standardized ?
if phone.startswith('+'):
mo = re.search(r'^\+\d{2,3}\.\d{9,11}$', phone)
if not mo:
raise forms.ValidationError(_(u'Vous devez entrer un numéro de téléphone. (+33.389520638 ou 0389520638).'))
else:
return phone
# If not, it must be a french number.
phone = re.sub("\D", "", phone) # Suppression des caractères séparateurs
mo = re.search(r'^\d{10}$', phone) # Numéro à 10 chiffres
if not mo:
raise forms.ValidationError(_(u'Vous devez entrer un numéro de téléphone. (+33.389520638 ou 0389520638).'))
else:
phone …Run Code Online (Sandbox Code Playgroud) 我想在FLEX和BISON做一点练习.
这是我写的代码:
calc_pol.y
%{
#define YYSTYPE double
#include "calc_pol.tab.h"
#include <math.h>
#include <stdlib.h>
%}
%start line
%token NOMBRE
%token FIN
%%
line: exp '\n' { printf("\t%.2lf\n", $1); };
exp: exp exp '+' { $$ = $1 + $2 ;}
| exp exp '-' { $$ = $1 - $2 ;}
| exp exp '*' { $$ = $1 * $2 ;}
| exp exp '/' { $$ = $1 / $2 ;}
| exp exp '^' { $$ = pow($1, …Run Code Online (Sandbox Code Playgroud) 我这里有一些代码:http : //bitbucket.org/natim/lo53_tp1/src/tip/part3/camions/medias/js/tracking.js
我用来绘制一些关于卡车方向的信息。
问题来自在 for 循环中定义的函数,如下所示:
...
for(i = 0; i < nb_trucks; i++)
{
...
contentString = '<div id="content">'+ trucks[i]['name'] + '</div>';
current_window = new google.maps.InfoWindow({
content: contentString
});
infosWindow.push(current_window);
current_marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(trucks[i]['end']['lat'], trucks[i]['end']['lon']),
draggable: false,
title: trucks[i]['name']
});
markers.push(current_marker);
google.maps.event.addListener(current_marker, 'click', function() {
current_window.open(map, current_marker);
});
}
Run Code Online (Sandbox Code Playgroud)
在这段代码中,您可以看到最后一个块
google.maps.event.addListener(current_marker, 'click', function() {
current_window.open(map, current_marker);
});
Run Code Online (Sandbox Code Playgroud)
我的问题是 addListener 参数中的 current_marker 与函数内部的不同。
函数内的 current_window 和 current_marker 在每次循环时都会被覆盖。
我怎样才能做对?
谢谢
我正在使用QListWidget显示QListWidgetItem的列表
此列表是从文件中读取的。关闭文件时,我想清空列表。
我对我做了这种方法:
class QuestionsList(QtGui.QListWidget):
def __init__(self, parent):
super(QuestionsList, self).__init__(parent)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.setProperty("showDropIndicator", False)
self.setAlternatingRowColors(True)
self.quiz = None
def loadQuiz(self, quiz):
self.quiz = quiz
self.flush()
if quiz is not None:
i = 1
for question in quiz.questions_list:
self.addItem(QuestionItem(i, question, self))
i += 1
def flush(self):
for item in [self.item(i) for i in xrange(self.count())]:
print unicode(item.text())
self.removeItemWidget(item)
del item
Run Code Online (Sandbox Code Playgroud)
loadQuiz方法有效,flush方法打印每个项目的文本,但removeItemWidget方法或del item都不能清空列表。
我怎样才能做到这一点 ?
谢谢
有没有办法使用 Elm 为页面构建组件,并在同一个 Elm 文件中编译两个组件,并使用相同的代码加载两次相同的组件?
你知道我该怎么做吗?
python ×5
django ×4
django-forms ×2
ada ×1
bison ×1
calculator ×1
django-admin ×1
elm ×1
favorites ×1
file-io ×1
flags ×1
flex-lexer ×1
http ×1
javascript ×1
pyqt ×1
pyside ×1
qt4 ×1
real-time ×1
web-services ×1