-2

Erorr

I wanna know where django search for index.html

Setting.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['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',
            ],
        },
    },
]

views.py

def index(request):
     return render(request, 'index.html', {})
Dharman
  • 30,962
  • 25
  • 85
  • 135
Deus Ralph
  • 23
  • 6
  • *I think this question is too broad and unclear*. Your `'DIRS': ['templates'],` is not correct, take a look at all the [answers](https://stackoverflow.com/a/25422131/5644965) from this SO question to configure that properly. Note that by default, Django will retrieve all your app templates inside the paths specified in `DIRS': ['/path/']` – Lemayzeur Jul 03 '18 at 01:24
  • I have the templates folder and I have index.html file... It work on local not in pythonanywhere.... – Deus Ralph Jul 03 '18 at 01:46
  • you need to specify the absolute path in your `DIRS`, join your `path` to the `BASE_DIR` of Django like the following: `'DIRS': [os.path.join(BASE_DIR, 'templates'),],` – Lemayzeur Jul 03 '18 at 01:52
  • It work............... but I can not validate your answer – Deus Ralph Jul 03 '18 at 02:05

3 Answers3

1

Django will look in the templates directory, that's if you created a folder called templates and if you have a file named index.html in the templates folder. For some reason I feel like the reason why you are asking this question is because you can not get your template to render when you run the server, am I correct? Please get back to me and I can do my best to fill you in so you can get your project working.

1

You can easily solve this problem: if the name of your project directory, where manage.py is in, is "RalphPortfolio", you need to make the following correction in settings.py:

'DIRS': ['RalphPortfolio/templates'],  
Dharman
  • 30,962
  • 25
  • 85
  • 135
Khosrow
  • 11
  • 1
1

add the full path to the template dirs for example if your path is /home/some_url/your_project/templates

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['/home/some_url/your_project_name/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',
            ],
        },
    },
]

it's because the path is not clear well and it will not find it.