help with URLS.PY

26 views
Skip to first unread message

randmw...@gmail.com

unread,
May 2, 2019, 5:21:59 PM5/2/19
to Django users
new to django. so i have an app that displays an html page. i also have a menu on that page that will load up other html pages.
however, when i add the path to urls.py and then the class def in views, it fails. i know it's something simple, what am i missing. 

As I said, the dashboard.html works, i just want another menu option to load the other html file. i have commented this out as it causes my app to break.



urls.py

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

from vr_reporting_app.views import HomeView
from vr_reporting_app.views import Map

urlpatterns = [
    path('', HomeView.as_view(), name='home'),    #points to the view in views.py 
    #path('map/', Map.as_view(), name='map'),                                                          
    path('admin/', admin.site.urls),
]


views.py

from django.shortcuts import render
from django.views.generic.base import TemplateView

class HomeView(TemplateView):
template_name = 'dashboard.html'

class Map(TemplateView):
template_name = 'map.html'

Chetan Ganji

unread,
May 2, 2019, 6:17:23 PM5/2/19
to django...@googlegroups.com
The line 
path('', HomeView.as_view(), name='home'),

Change it to below and try again.
path(''", HomeView.as_view(), name='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 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/8ef3e2d9-799e-4803-bd20-199300b373af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Abishek Goda

unread,
May 2, 2019, 10:19:08 PM5/2/19
to django...@googlegroups.com

Hi,


As I said, the dashboard.html works, i just want another menu option to load the other html file. i have commented this out as it causes my app to break.
So the issue is with the map url. Can you try to use a different name? 


    #path('map/', Map.as_view(), name='map'),               
path(‘map/‘, Map.as_view(), name=‘map-link’),

Or something like that?

Probably silly, but map is also a builtin. Maybe it conflicts?

Abishek

Rob W

unread,
May 3, 2019, 9:04:15 AM5/3/19
to django...@googlegroups.com
It does not, I changed the name, stil the same error



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

randmw...@gmail.com

unread,
May 3, 2019, 12:26:09 PM5/3/19
to Django users
I resolved this.

anchal agarwal

unread,
May 3, 2019, 3:41:48 PM5/3/19
to django...@googlegroups.com

I am also facing the same issue ,can you tell me how you resolved this issue?

> --
> 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/1e5029d2-a431-4c60-95ec-5ffedb11c124%40googlegroups.com.

Rob W

unread,
May 3, 2019, 3:48:39 PM5/3/19
to django...@googlegroups.com
Sure.

Here is my urls.py

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

from vr_reporting_app.views import HomeView
from vr_reporting_app.views import Local
from vr_reporting_app.views import User
from vr_reporting_app.views import School


urlpatterns = [
    path('', HomeView.as_view(), name='home'),
    path('User/', User.as_view(), name='user'),    
    path('Local/', Local.as_view(), name='local'),
    path('School/', School.as_view(), name='school'),                                                              
    path('admin/', admin.site.urls),
]

Here is my view.py

from django.shortcuts import render
from django.views.generic.base import TemplateView

class HomeView(TemplateView):
template_name = 'dashboard.html'

class Local(TemplateView):
template_name = 'local.html'

class User(TemplateView):
template_name = 'user.html'

class School(TemplateView):
template_name = ‘schoolreporting.html'

Also had to add {% load staticfiles %} to my html pages
And added a tag to each css reference.

<link href="{% static 'demo/demo.css' %}" rel="stylesheet" />

Reply all
Reply to author
Forward
0 new messages