上传具有非ASCII字符的文件时,我得到UnicodeEncodeError:
Exception Type: UnicodeEncodeError at /admin/studio/newsitem/add/
Exception Value: 'ascii' codec can't encode character u'\xf8' in position 78: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
查看完整堆栈跟踪.
我用MySQL和nginx以及FastCGI运行Django 1.2.
这是根据Django Trac数据库修复的问题,但我仍然遇到问题.欢迎任何有关如何修复的建议.
编辑:这是我的图像字段:
image = models.ImageField(_('image'), upload_to='uploads/images', max_length=100)
Run Code Online (Sandbox Code Playgroud) 我有模型,我只想创建一个实例,不应再允许实例.
这可能吗?我有一种感觉,我已经在某处看到过这种情况,但不幸的是我无法找到它.
编辑:我需要这个愚蠢的简单CMS.我有一个FrontPage和Page类继承的抽象类.我只想创建一个frontpage对象.
FrontPage对象和Page对象之间的区别在于它们应该具有稍微不同的字段和模板,并且如上所述,仅创建一个FrontPage.
在我的博客应用中,我想显示博客帖子列表以及与此帖子相关的第一张图片.现在我这样做:
{% for image in entry.image_set.all|slice:"1" %}
<img src="{{ image.get_absolute_url }}">
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
是否有我不知道的模板快捷方式,或者我应该写自己的经理?
当创建的jQuery对象我用下面的语法最近,描述在这里:
var $el = $('<div/>', {
class: 'class-1 class-2'
});
Run Code Online (Sandbox Code Playgroud)
Safari 5.0.5在我使用上述结构时出现语法错误.
删除第二个参数并使用addClass添加类会删除错误,但似乎相当不优雅.
你如何创建你的对象?我尝试使用attr({class:'class-1'}),但收到了相同的语法错误.
在完成Django教程之后,我现在正在尝试构建一个非常简单的开票应用程序.
我想在发票中添加几个产品,并在Django管理员的发票表单中指定每个产品的数量.现在,如果我有相同产品的不同数量,我将创建一个新的Product对象.
现在我的模型看起来像这样(公司和客户模型遗漏了):
class Product(models.Model):
description = models.TextField()
quantity = models.IntegerField()
price = models.DecimalField(max_digits=10,decimal_places=2)
tax = models.ForeignKey(Tax)
class Invoice(models.Model):
company = models.ForeignKey(Company)
customer = models.ForeignKey(Customer)
products = models.ManyToManyField(Product)
invoice_no = models.IntegerField()
invoice_date = models.DateField(auto_now=True)
due_date = models.DateField(default=datetime.date.today() + datetime.timedelta(days=14))
Run Code Online (Sandbox Code Playgroud)
我想数量应该从产品模型中排除,但如何在发票模型中为其创建一个字段?
我有一个简单的应用程序,用户应该在比赛结果上下注.比赛由两个队组成,一个结果和一个赌注.在Django管理员中创建与团队的匹配,参与者将填写结果和赌注.
必须根据数据库中的匹配动态生成表单.
我的想法是为每个匹配设置一个(Django)Form实例,并将这些实例传递给模板.
当我从django shell执行它时,它工作正常,但是当我加载视图时,实例不会呈现.
表单如下所示:
class SuggestionForm(forms.Form):
def __init__(self, *args, **kwargs):
try:
match = kwargs.pop('match')
except KeyError:
pass
super(SuggestionForm, self).__init__(*args, **kwargs)
label = match
self.fields['result'] = forms.ChoiceField(label=label, required=True, choices=CHOICES, widget=forms.RadioSelect())
self.fields['stake'] = forms.IntegerField(label='', required=True, max_value=50, min_value=10, initial=10)
Run Code Online (Sandbox Code Playgroud)
我的(初步)视图如下所示:
def suggestion_form(request):
matches = Match.objects.all()
form_collection = {}
for match in matches:
f = SuggestionForm(request.POST or None, match=match)
form_collection['match_%s' % match.id] = f
return render_to_response('app/suggestion_form.html', {
'forms': form_collection,
},
context_instance = RequestContext(request)
)
Run Code Online (Sandbox Code Playgroud)
我最初的想法是,我可以将form_collection传递给模板,并将循环传递给像这样的集合,但是id不起作用:
{% for form in forms %}
{% …Run Code Online (Sandbox Code Playgroud) 我需要对{% url %}模板标记创建的 URL 进行编码,以便将其作为参数传递到 iframe src 中,从而生成 Facebook Like 按钮。
这样做的合适方法是什么?该urlencode模板过滤器似乎并不在这里工作。我的模板代码如下所示:
{% url blog_urls/blog_detail slug=p.slug year=p.published_on.year month=p.published_on.month day=p.published_on.day %}
Run Code Online (Sandbox Code Playgroud) django ×6
django-admin ×3
attributes ×1
django-forms ×1
file-upload ×1
forms ×1
javascript ×1
jquery ×1
nginx ×1
python ×1