1

django-postman と django-messages をインストールした後、TemplateNotFound が表示されます。私は明らかにそれらを別々にインストールしました-最初にdjango-postman、次にdjango-messages。これはとても簡単ですが、これを解決するために何時間も費やしました。

私は Django 1.8 を使用しています。これは、pip を使用した新しいベース インストールです。次に、上記の2つのパッケージをインストールしました。私の settings.py ファイルの TEMPLATES 部分は次のとおりです。

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'), 
            #os.path.join(BASE_DIR, 'templates/django_messages'), 
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

INSTALLED_APPS タプル内に、上記のパッケージもインストールしました。

これがurls.pyへの私の追加です:

url(r'^messages/', include('django_messages.urls')),

システムに他の変更は加えられていませんが、/messages に移動すると、次のエラー メッセージが表示されます。

TemplateDoesNotExist at /messages/inbox/
django_messages/inbox.html
Request Method: GET
Request URL:    http://localhost:8000/messages/inbox/
Django Version: 1.8.3
Exception Type: TemplateDoesNotExist
Exception Value:    
django_messages/inbox.html
Exception Location: /projects/.virtualenvs/blatter/lib/python2.7/site-packages/django/template/loader.py in render_to_string, line 138
Python Executable:  /projects/.virtualenvs/blatter/bin/python
Python Version: 2.7.6
4

2 に答える 2

2

問題は、サイトの base.html から拡張されているためです。郵便配達員のドキュメントにも記載されています:- https://django-postman.readthedocs.org/en/latest/quickstart.html#templates

The postman/base.html template extends a base.html site template, in which some blocks are expected:

    title: in <html><head><title>, at least for a part of the entire title string
    extrahead: in <html><head>, to put some <script> and <link> elements
    content: in <html><body>, to put the page contents
    postman_menu: in <html><body>, to put a navigation menu

可能な解決策はここにあります:- django-postman extends a base.html that not exist

于 2016-03-10T15:39:55.867 に答える
1

呼び出されたテンプレートを確認し、extends/inheritance パラメータを変更した後、django-messages の問題が解決されました。

呼び出されていたファイル inbox.html は、「django_messages/base.html」を継承しています ... これは正常に機能しました。「base.html」は「base.html」から継承されたため、エラーの原因となる循環ロジックがここにあるように見えました。これはデフォルトであり、私が追加したものではありません。「base.html」から extends/inheritance 宣言を削除して、それ自体から継承しないようにすると、django-messages が機能しました。

おそらく、Django 1.8 はテンプレートを使用していくつかのロジックを変更しましたか? いずれにせよ、問題は解決しました。

于 2015-07-16T18:46:43.670 に答える