I'm completely new to django.It doesn't work well.


But I’m getting that general message instead of my own.

Hello!

Just a tip, please explain what you have done and what you need help with. Be precise, what do you want?

@abbasj I want something personalized and not a general message!
I’ve followed steps as given by ChatGPT 4o, but something is wrong.

I’ve created all the necessary subdirectories and run this command python manage.py runserver but I’m getting just this general page:

Everything seem to work fine, but if you want to render a template, you need to a view and a template. Have you created the template in the template folder?

I suggest you check the documentation where it is described, but you need to create a template folder inside you app like this:

Screenshot 2024-05-30 231023

I have created a template folder within the main_app. It is important that the folder is called templates, nothing else. Inside the template, create a second folder that has the same name as your app, nothing else. Add you template inside that folder.

In you views, do the following:

def ViewName(request):
   context = {}
   return render(request, "e.g main_app/you_template_name.html", context)

In you settings file, you must configure the following:

You are basically letting Django know where to search for the templates.

Now your personalized template will load.

Happy reading:

1 Like

Welcome @paxx0 !

For future reference to both you and @abbasj, please avoid posting images of code or other textual information. Copy / paste the text into the body of your post, surrounded between lines of three backtick characters.

Doesn’t work. At best what I would need is a .zip file with all the correct directory structure which I could unzip and use!

I welcome you to Django. Learning it has it challenges, but it’s very fulfilling.

Please explain what you have done, I’ll guide you to the best of my ability.

Thank you for your kind words!
I was unable to create a proper directory structure, so far I have this:

but I’m facing a general message instead of a personalized one.

I assume your app is called myapp. In that directory (encircled in blue), I don’t see any folder called templates.

Do the following:

  1. Creates a folder in the myapp directory. It must be named templates, nothing else.
  2. Inside the templates folder, create another folder called myapp (the name of you app).
  3. Configure the settings, specifically the part named TEMPLATES:
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',
            ],
        },
    },
]

Share your settings as well in you next reply.

I’ve slightly proceeded but not quite: MY PROJECT

Hi. I think ChatGPT might be trying to lead you astray here. You certainly don’t want to be utilizing Python subprocesses to open a Jupyter notebook while using the Flask framework together with the Django framework, especially if all you’re trying to do is get a simple message to show up on the screen. To get the message to display on the page, you can edit your myapp/views.py file to return the message directly from your view function, like so:

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world!")

Then you should see your message on the page.

My recommendation would be to ensure that all ChatGPT windows are completely closed and to follow the tutorial linked by @abbasj earlier, starting from part 1. If you’d like to do something a bit more involved than “Hello, world,” you can use Django templates as described earlier to write your HTML and use whatever directory structure you like for your templates. If your ultimate goal here is to create a complex website with images, JavaScript scripts, and CSS style sheets, you might be interested in hosting those files as static files, the basics of which are described in part 6 of that tutorial. Good luck and godspeed.

EDIT: And I dare say Django does indeed “work well.” It’s all about how you use it :slight_smile: