Django urls error

154 views
Skip to first unread message

lalit upadhyay

unread,
Apr 14, 2023, 6:07:38 PM4/14/23
to Django users

I have copied my code here.

Plz fix this error:



view.py
from django.http import HttpResponse


def hello_delhi_capitals(request):
return HttpResponse('Hello Delhi Capitals!')



myproject/urls.py

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

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



myapp/urls.py



from django.urls import path
from .views import hello_delhi_capitals

urlpatterns = [
path('hello/', hello_delhi_capitals, name='hello_delhi_capitals'),
]
2023-04-15.png

Muhammad Juwaini Abdul Rahman

unread,
Apr 14, 2023, 9:59:15 PM4/14/23
to django...@googlegroups.com
In your urls.py you use '/hello' but in your browser you type '/home'.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b157258f-6697-4bd7-81c7-48e425b4a1edn%40googlegroups.com.

lalit upadhyay

unread,
Apr 15, 2023, 4:27:36 AM4/15/23
to Django users
I have replaced URL ‘home/’ to ‘hello/’ but still i got same error
2023-04-15 (1).png

Karthik V A

unread,
Apr 15, 2023, 4:31:53 AM4/15/23
to django...@googlegroups.com
Remove admin/ url pattern at urls.py in myapp 

lalit upadhyay

unread,
Apr 15, 2023, 4:56:33 AM4/15/23
to Django users

I haven't used admin/ in my urls.py in myapp

from django.urls import path

from . import views

urlpatterns = [
path('', views.index, name="index"),
]

swazym...@gmail.com

unread,
Apr 15, 2023, 6:27:03 AM4/15/23
to django...@googlegroups.com
In ur views.py in the urlpatterns hello_delhi_capitals

Should be views. hello_delhi_capitals
Sent from my iPhone

On 15 Apr 2023, at 8:31 AM, Karthik V A <karthik...@gmail.com> wrote:



swazym...@gmail.com

unread,
Apr 15, 2023, 6:37:39 AM4/15/23
to django...@googlegroups.com
Try this let’s see
In your urls.py 
From . Import views
Then in ur urlpatterns
Set 

hello_delhi_capitals
To views. hello_delhi_capitals

Sent from my iPhone

On 15 Apr 2023, at 10:25 AM, swazym...@gmail.com wrote:

In ur views.py in the urlpatterns hello_delhi_capitals

lalit upadhyay

unread,
Apr 15, 2023, 8:54:42 AM4/15/23
to Django users
I have change views.py file but error not change
from django.urls import path

from . import views

urlpatterns = [
path('', views.hello_delhi_capitals, name='hello_delhi_capitals'),
]

2023-04-15 (1).png

Lawal Tobiloba Samuel

unread,
Apr 15, 2023, 11:05:38 AM4/15/23
to django...@googlegroups.com
What I notice is that wgen you are creating ur urls at the project level, you used "hello/" and you include the the app level urls.


If you want to request the route from the browser, you are suppose to use localhost:8000/hello, not localhost:home.



Remember: you did not create a route for "home"

--

Lawal Tobiloba Samuel

unread,
Apr 15, 2023, 11:05:38 AM4/15/23
to django...@googlegroups.com
So if you want to request you page, it will look like this, localhost:hello/hello.


At the app level of the urls, you can leave that path empty like this..... path(" ", views.delih......, name = "deliii....")


Then you can request you web page as localhost:/hello

b1t

unread,
Apr 15, 2023, 11:05:44 AM4/15/23
to Django users
ou haven't defined the home url that you are trying to access

አብርሃም መስፍን

unread,
Apr 15, 2023, 11:06:01 AM4/15/23
to django...@googlegroups.com
remove 'hello' from myapp.py to access the site  on 'hello' or you can access it at 'hello/hello' 

Lawal Tobiloba Samuel

unread,
Apr 15, 2023, 11:06:01 AM4/15/23
to django...@googlegroups.com
You are suppose to use localhost:8000/hello/hello.
Because, you added hello as you path when you are including the app urls to the project url and also you made hello the path to the view of hello_delhi_.... Which makes 2 hello's......

Use localhost:8000/hello/hello

b1t

unread,
Apr 15, 2023, 11:06:05 AM4/15/23
to Django users
You define hello/ in your base urls.py file and again in your  myapp/urls.py so that's create a URL like this "127.0.0.1/hello/hello".
instead use this in your myapp/urls.py 
urlpatterns = [
path('', hello_delhi_capitals, name='hello_delhi_capitals'),
]

Shaikh Mudassir

unread,
Apr 15, 2023, 11:06:32 AM4/15/23
to Django users
In  myproject/urls.py you have defined a path hello/ for myapp and then again you define hello/ for the hello_delhi_capitals method.
Now, You have two solution
2.  You can remove /home in myproject/urls.py
like this path('', include('myapp.urls'))

On Saturday, April 15, 2023 at 2:01:53 PM UTC+5:30 Karthik V A wrote:

b1t

unread,
Apr 15, 2023, 11:06:33 AM4/15/23
to Django users
You are trying to access the home/ URL which u haven't defined yet

Karthik V A

unread,
Apr 15, 2023, 11:13:48 AM4/15/23
to django...@googlegroups.com
Bro, From myapp/ urla.py


 Url pattern =[
Path('hello', views.hello_delhi_capitals, name = hello_delhi_capitals)] 


--
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.

Kasper Laudrup

unread,
Apr 15, 2023, 11:37:37 AM4/15/23
to django...@googlegroups.com
On 14/04/2023 21.48, lalit upadhyay wrote:
> *
>
> I have copied my code here.
>

The code is from a project called "myproject"

> Plz fix this error:
>

The error is from a project called "Tesing".

You can ignore all other answers you've been given so far until you
figure out how that could be.

Kind regards,
Kasper Laudrup
OpenPGP_0xE5D9CAC64AAA55EB.asc
OpenPGP_signature

lalit upadhyay

unread,
Apr 15, 2023, 11:59:26 AM4/15/23
to Django users

Can u brief me more about the error and how it resolve

oluwafemi damilola

unread,
Apr 16, 2023, 12:34:54 PM4/16/23
to django...@googlegroups.com
If you are still getting the error if you visit the 'hello' path, then you should visit 'hello/hello/'


On Sun, 16 Apr 2023 at 11:19, oluwafemi damilola <joshua...@gmail.com> wrote:
Your path is 'hello/', but in your browser you are going to 'home', that path does not exist

--
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.

oluwafemi damilola

unread,
Apr 16, 2023, 12:34:57 PM4/16/23
to django...@googlegroups.com
Your path is 'hello/', but in your browser you are going to 'home', that path does not exist

On Fri, 14 Apr 2023 at 23:07, lalit upadhyay <upadhya...@gmail.com> wrote:
--

Tahir Munir Faraz

unread,
Apr 17, 2023, 9:23:28 AM4/17/23
to django...@googlegroups.com
do not write hello at the project level This is not correct
path('hello/', include('myapp.urls')),
The code below is correct
path('' ",include("myapp.urls"),

Tarun Miri

unread,
Apr 17, 2023, 6:16:51 PM4/17/23
to django...@googlegroups.com
You may not write any string on the urls.py of myapp/urls.py 
Ex path('',hello_delhi_capitals,name="hello_delhi_capitals"),

ritik sahoo

unread,
Apr 22, 2023, 9:13:37 PM4/22/23
to django...@googlegroups.com

Nitesh Solanki

unread,
Apr 23, 2023, 12:21:44 PM4/23/23
to Django users
myproject (main app)
myapp (additional app)

Code: myproject/urls.py

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

from .views import HomeView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', HomeView, name='home'), ### will refer to main app views.py. These routes are commonly written in main app only
    path('hello/', include('myapp.urls')),
] ------------------------------------------
Code: myproject/settings.py
# Application definition

INSTALLED_APPS = [
    ...
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp', ### added to inform the django project that we have installed a new app named 'myapp'
]

------------------------------------------
Code: myproject/views.py
### refers to all the common route associated to main app (myproject)
from django.http import HttpResponse

def HomeView(request):
    return HttpResponse('Home page!')
------------------------------------------
Code: myapp/urls.py
### refers to all route which are associated with our new app 'myapp'. All routes declared here, can be accessed by adding a prefix '/hello/' ### because we have declared a word 'hello/' to refer 'myapp' in the 'myproject/urls.py'
from django.urls import path
from .views import hello_delhi_capitals

urlpatterns = [
    path('', hello_delhi_capitals, name='hello_delhi_capitals'),
]
------------------------------------------
Code: myapp/urls.py
### refers to all the common route associated to 'myapp' app
from django.http import HttpResponse

def hello_delhi_capitals(request):
    return HttpResponse('Hello Delhi Capitals!')
After running the project two urls will work here
Reply all
Reply to author
Forward
0 new messages