We’ve improved the security of our GitHub integration by migrating to GitHub Apps, for fine-grained permissions and read-only repo access. Why GitHub Apps?. Ever since the GitHub released GitHub Apps,…
Posted by Tim Graham on April 1, 2015 After more than a year of development, the Django team is happy to announce the release of Django 1.8 according to schedule. This version has been designated as a long-term support (LTS) release, which means that security and data loss fixes will be applied for at least the next three years. As always, the release notes cover everything in-depth, but some of t
Djangoのフォームを使ったテンプレート定義について簡単にメモ書きする。 Django 標準のフォーム用テンプレート言語を使用する as_p / as_ul / as_table はフォームに含まれるフィールドをセットで出力する。 またフィールドと一緒に変数名をラベルとして出力する(変数名のアンダーバーは空白に変換)。 as_p ・・・段落として表示する。 各フィールド及びラベルはセットで<p>タグによって包まれる。 as_ul ・・・リスト形式で表示する。 各フィールド及びラベルはセットで<li>ダグで包まれるが、<ul>もしくは<ol>タグは付加されないのでデザインの応じて付加する。 as_table ・・・テーブル形式で表示する。 各フィールド及びラベルは<td>、<th>及び<tr>ダグで包まれるが、<table>タグは付加されないので付加する必要がある。 使用例 <form a
I am trying to set the field to a certain value after the form is initialized. For example, I have the following class. class CustomForm(forms.Form): Email = forms.EmailField(min_length=1, max_length=200) In the view, I want to be able to do something like this: form = CustomForm() form["Email"] = GetEmailString() return HttpResponse(t.render(c))
ModelChoiceFieldの選択肢を動的に変えたいとき、__init__でself.fieldsを参照して入れ替えることができる class SelectForm(forms.Form): item = forms.ModelChoiceField(queryset=Item.objects.none()) def __init__(self, category, *args, **kwargs): super(SelectForm, self).__init__(*args, **kwargs) if category: qs = Item.objects.filter(category=category) self.fields['item'].queryset = qs ただ同じ方法でなんでも設定できるわけではなくて、例えばIntegerFieldのmin_valueやmax_
DjangoでModelChoiceFieldのquerysetを動的に指定するの余談に書いた内容について試してみたので、メモメモ。 前回の宿題 Form.fieldsをいじれば、他のフィールドのいろんな属性をフォーム生成後に変更することができる。 フィールドそのものを追加・削除することもできるかも? 実際にやってみた Djangoのshellコマンドを起動して、対話型シェル上で試していく 空っぽのFormオブジェクトを生成する >>> from django import forms >>> f = forms.Form() >>> f.as_p() '' >>> f.fields OrderedDict() この時点では何もフィールドが定義されていないので、as_p()をコールしても何もレンダリングされない Form.fieldsは空のOrderdDictオブジェクトが表示されるのみ
Testing AJAX Views in Django¶ A lot of the Django code we use at work has a special case for AJAX. It has been a kind of a pain to test, because the test client by default doesn’t use AJAX. Luckily the is_ajax call in the Django HttpRequest object is a simple check of an HTTP Environmental variable. An undocumented feature of the Django Test Client is that you can pass in custom HTTP ENV variables
Thu 07 March 2013 By Beno�t Bryon How to test views of a Django application? Django's builtin test client is not suitable for unit testing! It performs system tests: it handles your views as a black box in a project's environment. This article provides a recipe for developers to replace Django's builtin test client by smaller, fine-grained, view-centric tests. self.client.get(): system tests for t
I'm trying to build a test for a view that's decorated with @login_required, since I failed to make it work, I did a simple test and still can't make it pass. Here is the code for the simple test and the view: def test_login(self): user = self._create_new_user() self.assertTrue(user.is_active) login = self.client.login(username=user.username, password=self.data['password1']) self.failUnless(login,
So I have my TagStatus model. I'm trying to make a ModelForm for it. However, my form requires that the hidden input be populated with the {{ tag.name }}. I've been looking through the docs and I don't know how to make the tag field a hidden input. Perhaps a ModelForm isn't the way to go? models.py: class TagStatus(models.Model): user = models.ForeignKey(User, null=True, unique=True) status = mode
It seems that cleanly and easily doing AJAX views in Django is an area that gives a lot of people trouble. We like to do views as straight HTTP if at all possible, but there are always interactions that would be better served by not having a page load. We're also big fans of django-tastypie but it's a whole other ball of wax on its own, especially if you want to have views that write to the databa
Django はコードとテンプレートの双方で国際化をフルサポートしています。このド キュメントでは国際化の仕組みについて説明します。 概要¶ 国際化のゴールは、一つの Web アプリケーションが複数の言語でコンテンツや機能 を提供できるようにすることにあります。 Django 開発者は、最小限のフックを Python コードとテンプレートに埋め込むこと で国際化というゴールにたどり着けます。これらのフックは 翻訳文字列 (translation string) と呼ばれています。翻訳文字列は Django に「このテキストについてエンドユーザの言語に合ったテキストがあるなら、テキ ストを翻訳して出力せよ」と指示します。 Django はこれらのフックに注意して、ユーザの言語設定に合わせて Web アプリケー ションをオンザフライで翻訳します。 Django が行っているのは、本質的には以下
自動エスケープ機能を制御します。このタグは引数に on または off を取 り、ブロック内の自動エスケープの有効・無効を決定します。 自動エスケープがオンの場合、変数の値は全て、最終的な文字列出力になる直前に HTML エスケープされます (他のフィルタは先に適用されます)。この動作は、 変数に escape フィルタを手動で適用した場合と同じです。 例外として、変数をテンプレートに挿入するコードや、 safe, escape と いったフィルタの適用によって、 “safe” マーク済みの変数はエスケープされませ ん。
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く