problems with url and views - new to django

28 views
Skip to first unread message

Rob W

unread,
Apr 21, 2019, 6:07:49 PM4/21/19
to Django users
setting up a new project.
all good, loaded up the project on localhost.

however, when creating a view then setting the url, it doesn't work.


urls.py

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

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

views.py

from django.shortcuts import render

def hello(request):
   return render(request, "lct_app/templates/hello.html", {})

i comment out the path in urls.py, django comes back. what am i missing?



Victor H. Velasquez Rizo

unread,
Apr 21, 2019, 9:02:34 PM4/21/19
to django...@googlegroups.com
Hello Rob.
With the url "hello/", your trying to call the "hello" function on your view.py.
First, you need to import "hello" to be able to use it. from  from  lct_app.views import hello
Second, call the function. path('hello/', hello),

urls.py
from django.contrib import admin
from django.urls import path
from  lct_app.views import hello

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

views.py

from django.shortcuts import render

def hello(request):
   return render(request, "lct_app/templates/hello.html", {})
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4872beca-597c-4689-a12e-9e888c5266ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--



Atte...,.
Vìctor Hugo Velàsquez Rizo
Cali - Colombia

Robert Wahoo

unread,
Apr 22, 2019, 11:32:03 AM4/22/19
to django...@googlegroups.com

Awesome,Thanks Victor, I’ll give this a shot.

 

Thanks.

Robert Wahoo

unread,
Apr 22, 2019, 12:38:38 PM4/22/19
to django...@googlegroups.com

Actually, I found why I got that last message, was a typo on my part.

 

On to the next problem…Thank you.

 

From: "django...@googlegroups.com" <django...@googlegroups.com> on behalf of "Victor H. Velasquez Rizo" <rizo....@gmail.com>
Reply-To: "django...@googlegroups.com" <django...@googlegroups.com>
Date: Sunday, April 21, 2019 at 9:02 PM
To: "django...@googlegroups.com" <django...@googlegroups.com>
Subject: Re: problems with url and views - new to django

 

Hello Rob.

Deepali Singh

unread,
Apr 23, 2019, 8:13:31 AM4/23/19
to django...@googlegroups.com
I have new to django ad i have created my project my pieshop,,,,I don't know how it is showing 3 folders in the app

Victor H. Velasquez Rizo

unread,
Apr 23, 2019, 11:07:10 AM4/23/19
to django...@googlegroups.com

Victor H. Velasquez Rizo

unread,
Apr 23, 2019, 11:07:32 AM4/23/19
to django...@googlegroups.com
Whats the structure of your project.?

Rob Gmail

unread,
Apr 23, 2019, 11:09:04 AM4/23/19
to django...@googlegroups.com
Yes I did

Rob 
Sent from my mobile device, please excuse the typos. 
Reply all
Reply to author
Forward
0 new messages