Issue
My view was running fine until Ill tried to override an admin view. Which i eventually got to work. However in the process I broke the path to my view that was working. The admin view had nothing to do with my originally working view.
Now I copied my view into every possible level of my project structure. Yet the django template loader fails to find my order_input.html
The error shows the correct path to my order_input.html. I made copies of order_input.html at every single possible level of my project... but django still cant find it.
APP - URLS.PY
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^hw/$', views.helloworld, name='helloworld'),
url(r'^order_input/$', views.order_input, name='order_input'),
url(r'^time/$', views.today_is, name='time'),
url(r'^$', views.index, name='index'),
]
SETTINGS.PY
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
# 'django.contrib.staticfiles',
'import_export',
'hw_app',
]
PROJECT URLS.PY
urlpatterns = [
url('r', include('hw_app.urls')),
url('admin/', admin.site.urls),
path('clearfile', views.clearfile),
path('readfile', views.readfile),
path('writefile', views.writefile),
path('helloworld', views.helloworld),
path('order_input', views.order_input),
path('ajax_view', views.ajax_view),
]
Solution
You have the order_input url defined in both your project and your app urls.py files, only in the hw_app version it has a trailing slash. The slashless project URL may be looking in the wrong places for things as it will assume there is a related view at its level.
Try removing that path from the project urls.py file. Assuming it should be going to the same place, it's already included when you include(hw_apps.urls) (as url() is just a more up-to-date path() ). Then try calling the page with a trailing slash.
The only view file then relevant should be hw_apps/views.py. For consistency place the HTML template file is in hw_app/templates/hw_app/order_input.html so you know django should be able to find it.
Answered By - SamSparx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.