Home Cannot get PyCharm Django project to read and display Django Templating Language Tags
Reply: 2

Cannot get PyCharm Django project to read and display Django Templating Language Tags

Dupeydoo
1#
Dupeydoo Published in 2017-12-07 11:03:21Z

I have been pulling my hair out over this, am new to using Django for web development and I have never setup a Django project in PyCharm. It is Django v2.0 and PyCharm 2017.3.

I have a basic project which consists of two apps, for examples sake lets call one Test and one TestProj. Test is the core of the site where settings.py is located, and TestProj is where I wish to add templates.

The Test urls.py points to the TestProj urls.py, which when requested, serves a html file to the root url of the site. This content is located in a folder again called Test which is located in a templates folder in TestProj

Essentially the directory structure is as follows:

Test  >
    settings.py etc
TestProj  >
    templates  >
        Test  >
            index.html
            header.html
    other python files are here!

The index.html file is served fine but the problem occurs when I try to use Django templating to link in another html file. This is index.html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Test</title>
    </head>
   <body>
       <div>
           {% block content %}
           {% endblock %}
       </div>
   </body>
</html>

And this is header html which is located in the same templates directory:

{% extends 'Test/index.html' %}

{% block content %}
    <p>Hello World</p>
{% endblock %}

index.html is served as normal but for some reason no matter what I do the Django {% block content %} in index.html doesnt seem to evaluate. Thus, my index.html, when served in the browser with Pycharm, has an empty body instead of Hello World.

The Test folder within templates is marked as a template folder in PyCharm so I don't see why this is the case. I also have Django selected as the template language in PyCharm settings and I have tried reinstalling PyCharm. The settings.py templates is also correctly configured to my knowledge as below:

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

Any help would be very much appreciated!

Farrukh
2#
Farrukh Reply to 2017-12-07 14:58:34Z

make sure that you set "Project Interpreter" correctly: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html

Dupeydoo
3#
Dupeydoo Reply to 2017-12-08 10:15:22Z

I've fixed this, turns out it was stupidity in my views. I was linking to index.html when rendering instead of header, which is supposedly how extends works.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308126 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO