Всякий раз, когда я устанавливаю перенаправление в другое определенное представление, я получаю ошибку пространства имен.У меня определено имя app_name в urls.py, но я почти уверен, что мне не хватает чего-то очевидного.
Ошибка:
enter code here`Traceback (most recent call last):
File "/root/areports/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/root/areports/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/root/areports/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/root/areports/reports/views.py", line 15, in entry_create_view
return HttpResponseRedirect(reverse('reports:new_district_view'))
File "/root/areports/venv/lib/python3.6/site-packages/django/urls/base.py", line 86, in reverse
raise NoReverseMatch("%s is not a registered namespace" % key)
django.urls.exceptions.NoReverseMatch: 'reports' is not a registered namespace
views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
from .forms import New_Event_Form, New_District_Form
def entry_create_view(request):
form = New_Event_Form(request.POST or None)
if form.is_valid():
form.save()
#form = New_Event_Form()
context = {
"form": form
}
return HttpResponseRedirect(reverse('reports:new_district_view'))
else:
print('Invalid')
context = {
'form': form,
}
return render(request, "entry_create.html", context)
def new_district_view(request):
new_district = New_District_Form(request.POST)
if new_district.is_valid():
new_district.save()
new_district = New_District_Form()
context = {
"new_district": new_district
}
return render(request, "new_district.html", context)
else:
print('Invalid')
context = {
"new_district": new_district
}
return render(request, "new_district.html", context)
def home_view(request):
return render(request, "home.html", {})
urls.py
from django.contrib import admin
from django.urls import path
from reports import views
app_name = 'reports'
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home_view, name='home'),
path('home/', views.home_view, name='home'),
path('create/', views.entry_create_view, name='create_event'),
path('district/', views.new_district_view, name='new_district_view')
]
Я подозреваю, что проблема связана со структурой папок моего проекта, поэтому я добавляю сокращенное дерево ниже.
areports
|--areports
| |--settings.py
| |--urls.py
|
|--reports
| |--static
| |--templates
| | |--(all project templates)
| |--admin.py
| |--apps.py
| |--forms.py
| |--models.py
| |--views.py
|
|--db
|--manage.py