Viewing posts for the category Django
Alpine の Docker 環境で、Django Cartridge のテストに失敗していた
freezegun は、python のライブラリ。
Vue で開発する際、webpack dev server を起動していて、API バックエンドに Django を使っていて、Django の認証に Python social auth + 外部 Auth プロバイダを使っているケース。
Django==1.9.13
Mezzanine==4.3.0
Django: Best way to unit-test an abstract model - Stack Overflow
https://stackoverflow.com/questions/4281670/django-best-way-to-unit-test-an-abstract-model
Django Social Auth の Django モジュールや AllAuth のリダイレクト先プロトコルスキームが HTTPS ではなく HTTP になって困った
(callback_uri, redirect_uri, destination)
※ RDBの制約を作るという意味ではないです。とりあえず動く ForeignKey フィールドを作るという意味です。
Django で、
Django で、モデルの Meta: managed = False
にすると、他の App からのユニットテストの時、create() などしようとすると
Python2.7 + Django 1.6 のプロジェクトを、Python3.5 + Django2.0 にしてマイグレーションファイルを作り直し、./manage.py migrate したら
ubuntu 14.04
いつも焦るので書いておく
Django SJISのCSVをダウンロードさせるビュー基底クラス
SimpleListFilter を使って簡単に書ける
けっこう何回もミスってしまうのでメモ。
元々は
AWS ELB -> Apache2 -> mod_wsgi という構成だったが、
AWS ELB -> Apache2 -> uwsgi と、Djangoサーバを uwsgi に変えたら、
ログインフォームを送信する時など、django csrf 認証に失敗するようになった。
DEBUG = True で見てみると
アクセス禁止 (403)
CSRF検証に失敗したため、リクエストは中断されました。
Help
Reason given for failure:
Referer checking failed - https://example.com.com/some-path/ does not match any trusted origins.
In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure:
Your browser is accepting cookies.
The view function passes a request to the template's render method.
In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.
You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.
You can customize this page using the CSRF_FAILURE_VIEW setting.
ELB で HTTPS を受け、Apache には 80 でリクエスト、uwsgi は HTTP プロトコルをリッスンしている(uwsgiプロトコルではない)
Apacheの設定は
ProxyPass / http://127.0.0.1:8081/
ProxyPassReverse / http://127.0.0.1:8081/
Alias /static/ /var/django/xxxxx/staticfiles/
ProxyPass /static/ !
こんな感じ。
Django のコードを検索してみると
csrf.py
REASON_BAD_REFERER = "Referer checking failed - %s does not match any trusted origins."
こうなっていて、コードを読んで見ると CSRF_TRUSTED_ORIGINS にドメインを入れれば良いっぽい。
CSRF_TRUSTED_ORIGINS = [".example.com"] これで良い
Python 3, Django 1.9
/url-path-before/feature/hoge/ にアクセスした人を、 /url-path-after/feature/hoge/ にリダイレクトしたい。
Django に標準搭載の django.views.generic.TemplateView。
これまでいろんなグッズを作ってきたけど、今回は「お米」と聞いて買うしかないなと。今夜の夕食はコシヒカリ!箸もセットだし^^ https://t.co/01ucQx9qtw #腰乃展 #マンガ展 https://t.co/4VL2vOe0Og
1 year, 3 months ago
講談社さんとやった全部入り電子書籍セットがギネスブックに登録されたよー https://t.co/rbkd3IYub0
1 year, 3 months ago