-1

I'm a newbie in Django, and I created a project "first pycharm" with structure like that:

    \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

my first pycharm use an application has name "app" with settins.py has content:

..........

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',



            ],
        },
    },
]

My issue that I can access all html file in app/templates/app/. But when I create 1 folder as report in app/templates/app/report, I can't access to report/audiance_overview.html.

Please help me access them.

Thanks, Jame

Jame H
  • 1,324
  • 4
  • 15
  • 26

2 Answers2

0

You seem to be confusing file path and url, which are two different things in Django (if you come from the php world for instance, it's not the same behaviour). If you're running the django development server, you won't be able to access templates that way.

In short, you need to define a url in urls.py that points to a view, say in views.py, which in turn will call the template. See https://docs.djangoproject.com/en/1.11/intro/tutorial03/ for a detailed example of how this works.

It may seem heavy at first, but this gives you much better control over your url scheme, as it's freed from any filesystem constraints.

Laurent S
  • 4,106
  • 3
  • 26
  • 50
0

Note: Please check that you have added the application inside the INSTALLED_APPS array.

My scenario :

project name = farm

app name = home

so inside farm folder(root location), there is a file with the name settings.py , now inside this file you get an array with the name of INSTALLED_APPS now add a new app('home') in this array. Like:

 # Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'home' #its add by me
]