I am trying to create an url which redirects to a simple static .html file using:
url(r'^impressum/', TemplateView.as_view(template_name='impressum.html'), name='impressum'),
As far as I understand the template_name argument takes the location of the .html file. I tried several variations of the above code, trying to redirect to the file but always get a 404 error when loading localhost:8000/impressum/
This is how my Folder directory looks. I tried "lwc/templates/impressum.html" and "templates/impressum.html". What am I doing wrong / how does this path direction work exactly
EDIT: below my TEMPLATE_DIRS settings:
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
I managed to find my error:
this is how my urls.py looked:
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'joins.views.home', name='home'),
url(r'^(?P<ref_id>.*)$', 'joins.views.share', name='share'),
url(r'^impressum/$', TemplateView.as_view(template_name='impressum.html')),
)
I put the impressum url on the top and then it worked out. I remembered from a tutorial that there is a certain logic how django checks the urls line by line and if you have an url with an extension you have to put before the url without any in order to make it work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With