viewflow / django-material

Material Design for Django
http://viewflow.io/
BSD 3-Clause "New" or "Revised" License
2.49k stars 424 forks source link

django.urls.exceptions.NoReverseMatch: Reverse for 'cameramodel_add' not found. #523

Open djjudas21 opened 2 years ago

djjudas21 commented 2 years ago

I've started trying to reimplement a UI with django-material again from scratch. I'm running into an error and I've put quite a lot of time into trying to figure it out, but I can't make progress.

I assume cameramodel_add has the _add suffix automatically added by the ModelViewSet, but somehow the autoloading isn't working?

The schema app used to contain a bunch of views I wrote myself, but I have now deleted everything apart from models.py and the migrations.

# camerahub/urls.py

from django.contrib import admin
from django.urls import include, path
from material.frontend import urls as frontend_urls

urlpatterns = [
    path('', include(frontend_urls)),
    path('', include('schema.urls')),
    path('api/', include('api.urls')),
    path('admin/', admin.site.urls),
    path('accounts/', include('django_registration.backends.activation.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('', include('django_prometheus.urls')),
    path('ratings/', include('star_ratings.urls', namespace='ratings')),
    path('health/', include('health_check.urls')),
]
# ui/urls.py

from unicodedata import name
from django.urls import path, include
from django.views import generic

from . import views

urlpatterns = [
    path('', generic.TemplateView.as_view(template_name="index.html"), name="index"),
    path('cameramodel/', include(views.CameraModelViewSet().urls)),
]
# ui/views.py

from material.frontend.views import ModelViewSet

from schema import models

# class MyModelViewSet(ModelViewSet):
#    model = models.MyModel

class CameraModelViewSet(ModelViewSet):
    model = models.CameraModel

Trying to browse to http://127.0.0.1:8000/ui/cameramodel/ I get

Internal Server Error: /ui/cameramodel/
Traceback (most recent call last):
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/material/frontend/views/list.py", line 531, in dispatch
    return super(ListModelView, self).dispatch(request, *args, **kwargs)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/material/frontend/views/list.py", line 357, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/material/frontend/views/list.py", line 315, in get
    context = self.get_context_data()
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/material/frontend/views/list.py", line 521, in get_context_data
    kwargs['add_url'] = reverse('{}:{}_add'.format(opts.app_label, opts.model_name))
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/django/urls/base.py", line 86, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/camerahub-FNy4MBnC-py3.10/lib/python3.10/site-packages/django/urls/resolvers.py", line 698, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'cameramodel_add' not found. 'cameramodel_add' is not a valid view function or pattern name.
"GET /ui/cameramodel/ HTTP/1.1" 500 117163

Originally posted by @djjudas21 in https://github.com/viewflow/django-material/issues/513#issuecomment-1110268057