問題タブ [django-context]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
django - テンプレートのdjangoアクセスコンテキスト
私のコードは次のようなものです: コンテキストをカスタマイズし、テンプレートに設定されたクエリにアクセスしたい
問題は、テンプレートの get_queryset メソッドによって返されるクエリセットにアクセスする方法です。Studentinfo.can_show_distribute などのカスタム属性にアクセスできることはわかっていますが、クエリ データにアクセスするにはどうすればよいですか?
python - Django last visited urls list
I'm writing django-based forum, and i've decided it would be suitable for user to browse his last pages. Also, user tracking middleware can be a good aid for suggestions, and so on.
I think, the easiest way to do it is to use the
Django Middleware
, but i ran into a problem: how to get the title of the page being rendered? Overrideprocess_template_response
? Can i get the{% block title %}
there?The second server-side way is to use a template tag, i think. In the easiest case, it should should look like
{% block title %}{% last_visited _("Page title") %}{% endblock %}
.The third, stupid way: make an ajax script, that will push current user's opened page with title into his session. So, this method will just avoid us getting the page title.
I think, the right way is to get the title
block from a template context in middleware. How can i do it?
Thanks.
UPDATE
Made the gist with realisation of the second method using templates
and django.cache
. The simplest usage:
Also, i'm still looking for a method allows to get the page's {% block title %}
in the middleware. Of course, i can use, i.e., lxml
parser and get the title
in the process_response
method, but it is an ugly overkill.
Thanks for any advice.
django - テンプレートタグのリクエスト変数を読む
私は Django プロジェクトを多言語サイトに変えようとしています。そのためにcountries-for-django
( github ) パッケージを採用しようとしています。
テンプレートタグの 1 つで、コードはセッション変数django_country
(ここから取得) を読み取ろうとしていますが、Django 1.5request
はコンテキストから変数を読み取ることに失敗します。
template タグのコードは次のとおりです (コードは最初の投稿から拡張されています)。
変数をcontext
出力すると、出力に変数が含まれませんrequest
。Django Toolbar
ただし、変数が存在することがわかります。
Django 1.5でコンテキスト変数の読み方が変わりましたか? ドキュメントには何も見つかりませんでした。
完全を期すために追加された Views.py とテンプレート。
ビュー.py
home.html
django - コンテキストプロセッサがdjangoのすべてのビューに追加されるのはなぜですか?
すべてのテンプレートに変数が渡されるように、コンテキスト プロセッサを作成しました。
私のsettings.pyは次のようになります:
単一のビューで私は渡します:
また、プロセッサを挿入すると、サイトのすべてのビューでトリガーされます。ビューからリクエストコンテキストを渡したときにのみヒットすると思いましたか?
私が行くすべてのビューに表示されるコードは次のとおりです。
特定のビューでのみコンテキスト プロセッサをトリガーするにはどうすればよいですか?
django - Django FormView にはフォーム コンテキストがありません
FormView 派生クラスを定義する場合:
が定義されているため、この行context['form'] = MyForm
は必要ないと思っていましたが、それがないとテンプレートに渡されません。
私が間違っていることは何ですか?form_class
{{ form }}
python - djangoにデフォルトのテンプレート変数のリストはありますか?
django テンプレートには、データを送信しなくても特定の変数が既に渡されていることに気付きました。たとえば、レンダリング時に「user」データをテンプレートに送信せずに「user」変数を呼び出すことができます。
これらの「デフォルト変数」のリストを見つけることができる場所はありますか?
django - Django クラス ベースのビューでコンテキスト データからフォームフィールドの初期値を設定する
アクティベーション キー ( /user/activate/123123123 ) を含むアクティベーション URL があります。それは問題なく動作します。get_context_data は、それをテンプレートにうまく組み込むことができます。私がやりたいのは、キーフィールドの初期値としてそれを持っているので、ユーザーは登録時に作成されたユーザー名とパスワードを入力するだけで済みます。
フィールドをテンプレートにハードコーディングせずに、コンテキストまたは get() からキーを取得するにはどうすればよいですか?
django - Django のコンテキストとは何ですか?
私はジャンゴの初心者なので、コンテキストとコンテキストプロセッサの概念を理解しようとしています。
- コンテキストとは何ですか? なぜ使用するのですか?
- コンテキストは、テンプレートで使用するために必要な値ですか?
- コンテキストとコンテキスト プロセッサは同じですか?
私はあなたの応答に感謝します。前もって感謝します!