2017-12-13 3 views
0

のテンプレートのフォルダにアクセスすることができない私はジャンゴで初心者だ、と私はそのような構造を持つプロジェクト「最初pycharm」作成:ジャンゴ:特定のアプリケーション

\firstpycharm 
| manage.py 
| views.py 
+---firstpycharm 
| | middleware.py 
| | models.py 
| | settings.py 
| | urls.py 
| | wsgi.py 
| | __init__.py 
| | 
| +---__pycache__ 
+---app 
| | models.py 
| | models.pyc 
| | urls.py 
| | views.py 
| +---migrations 
| +---static 
| | +---build 
| | +---images 
| | +---vendors 
| +---templates 
| | **\---app 
| |  | base_site.html 
| |  | base_site_bk.html 
| |  | index.html 
| |  | index2.html 
| |  | index3.html 
| |  | index_bk.html 
| |  | invoice.html 
| |  | level2.html 
| |  | login.html 
| |  | map.html 
| |  | media_gallery.html 
| |  | morisjs.html 
| |  | other_charts.html 
| |  | page_403.html 
| |  | page_404.html 
| |  | page_500.html 
| |  | plain_page.html 
| |  | pricing_tables.html 
| |  | profile.html 
| |  | projects.html 
| |  | project_detail.html 
| |  | sidebar.html 
| |  | tables.html 
| |  | tables_dynamic.html 
| |  | top_navigation.html 
| |  | typography.html 
| |  | widgets.html 
| |  | xx.html 
| |  \---report 
| |    audiance_overview.html** 
+---static 
| \---script 
+---staticfiles 
| \---admin 
|  +---css 
|  +---fonts 
|  +---img 
|  | \---gis 
|  \---js 
|   +---admin 
|   \---vendor 
|    +---jquery 
|    \---xregexp 
+---templates 

私の最初のpycharmの使用を私はアプリ/テンプレート/アプリケーション/内のすべてのhtmlファイルにアクセスすることができ

.......... 

INSTALLED_APPS = [ 
    'django_cassandra_engine', 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'django_extensions', 
    'app', 
    'firstpycharm', 
] 

.......... 
TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR, 'templates'), 
       ], 
     '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', 



      ], 
     }, 
    }, 
] 

私の問題:アプリケーションがsettins.pyと名称「アプリ」は、コンテンツを持っています。しかし、app/templates/app/reportに1つのフォルダをレポートとして作成すると、report/audiance_overview.htmlにアクセスすることはできません。

私はそれらにアクセスしてください。 Djangoの2つの異なるものです

おかげで、 ジェームズ

+0

「アクセスできません」という意味はどうですか?どちらの方法でファイルにアクセスしようとしていますか?テンプレートでは? url.py?ビューで? – nakiya

+0

私はlocalhost:8000/index.htmlでアクセスすることはできませんが、localhostにアクセスすることはできません:8000/report/audiance_overview.html –

+0

'urls.py'をここにコピーできますか? – nakiya

答えて

0

あなたはファイルのパスとURLを混乱しているように見える、(あなたは、例えば、PHPの世界から来た場合、それは同じ動作ではありません)。 django開発サーバーを使用している場合、そのような方法でテンプレートにアクセスすることはできません。

要するに、ビューを指すurls.pyのURLを定義する必要があります(例:views.py)。このURLはテンプレートを呼び出します。これがどのように機能するかの詳細な例については、https://docs.djangoproject.com/en/1.11/intro/tutorial03/を参照してください。

最初は重いように見えるかもしれませんが、これはファイルシステムの制約から解放されているため、あなたのURLスキームをよりよく制御できます。

関連する問題