0
votes

i'm learning django and i'm making a blog tutorial but it's from older version that i have, i have version 2.0.2 and i'm not understand documentation my problem is that i dont know how configure my urls.py this is my three proyect: proyect three

i need to put archive.html in 127.0.0.1:8000/ and this is my urls code

codigofacilito/blog.urls.py :

"""codigofacilito URL Configuration

The urlpatterns list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin<br/>
from django.urls import path<br/>
from . import views<br/>


urlpatterns = [
    path('admin/', admin.site.urls),

]

and codigofacilito/codigofacilito.urls.py:

from django.contrib import admin
from django.urls import path
from . import views



enter code here`urlpatterns = [
    path('admin/', admin.site.urls),

]
1
Can you be more specific.. What is that you want to do, and what is already done? I am myself a django starter and propably went though the same trouble as you are nowVipin Mohan
If you don't know how to map a URL to a view, you should read the tutorial where all this is clearly explained.Daniel Roseman
im learning tutorial but all is for older versionsSinother
In Django 2.0.2 you can still use url() as your tutorial does. You don't have to switch to path().Alasdair

1 Answers

1
votes
from django.views.generic import TemplateView

urlpatterns = [
    path('', TemplateView.as_view(template_name = 'archive.html')),
    path('admin/', admin.site.urls),

]

put this in your project's urls.py, this will directly render the archive.html when you visit 127.0.0.1:8000/ in your browser.

but if you want to render data from backend in this html page then i suggest you to use views (function based , class based, etc..)

then you just have to import the views in url file and specify path for that.

from your_app.views import your_view

urlpatterns = [
    path('/', your_view),
]