I am trying to attach hobbieswithCSS.html file to my website, while using Django. I am a beginner when it comes to Django, so I have naturally came across some problems (in the title) like this.
I have this anchor tag on my homepage -
<a href="{% url 'basic_app:hobbieswithCSS.html' %}">My Hobbies</a>
I have this view in my views.py file -
def hobbieswithCSS(request):
return render(request,'basic_app/hobbieswithCSS.html')
I think, that the main problem will be with the urlpatterns in urls.py file, because I am not sure how to set it up. These are my urlpatterns -
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^admin/', admin.site.urls),
url(r'^basic_app/',include('basic_app.urls')),
url(r'^logout/$',views.user_logout,name='logout'),
url(r'^$', views.hobbieswithCSS, name='hobbieswithCSS'),
]
Could anybody please tell me, how could I change the code in order to make that hobbieswithCSS.html file display, when I am trying to run it on my server?
It must be:
<a href="{% url 'hobbieswithCSS' %}">My Hobbies</a>
Without basic_app
.
Also you have the same path for index and hobbies . You have to change your url path:
urlpatterns = [
url(r'^$', views.index, name='index'),
...
url(r'^hobbies/$', views.hobbieswithCSS, name='hobbieswithCSS'),
]