Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Connect View to URL | Write the First Page
Django: First Dive
course content

Contenido del Curso

Django: First Dive

Django: First Dive

1. Get Started
2. Write the First Page
3. Models
4. Working with Database
5. Templates
6. Request Handling

bookConnect View to URL

Let's connect your View (page) to app URL.

Open the created urls.py file inside the app folder (in our case new_app folder).
It's a new file, so it will be empty.

Create the app_name and urlpatterns variables:

In Django, the app_name variable is used to specify the application namespace for URL names within a Django app. It is defined in the urls.py file of the app. Here's a description of the app_name variable:

  • The app_name variable is a string that represents the namespace of the Django app.
  • It is used to create a unique identifier for the app's URLs to avoid naming conflicts with URLs from other apps in the project.
  • By setting the app_name, you can refer to specific URL patterns using the app's namespace in the Django Tamplate Language (should be described later).
  • The app_name should be unique and preferably descriptive, reflecting the purpose or name of the app.

We have the implemented hello_world_view in views.py file:

Import this view to the urls.py and add path to urlpatterns:

Now we have access to this page via URL:

If you want to use the app1 as endpoint URL, you can write the empty string into urlpatterns:

Now, the access to this page provided by URL:

At this point, our View is connected, and we can safely modify it:

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 3
We're sorry to hear that something went wrong. What happened?
some-alt