0
votes

When i type http://127.0.0.1:8000/groups/ to the browser, I get NoReverseMatch at /groups/ and'

enter image description here

Environment:

Request Method: GET Request URL: http://127.0.0.1:8000/groups/

Django Version: 2.2.5 Python Version: 3.8.0 Installed Applications: ['groups', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'bootstrap3', 'accounts', 'posts'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template error: In template C:\Users\User\Desktop\fullstack\django\simplesocialatom\simplesocial\templates\base.html, error at line 12 ' 4 : 5 : 6 : Star Social
7 : 8 : 9 :
10 : 11 : 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 20 : 21 :
22 :

Traceback:

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\urls\base.py" in reverse 75. extra, resolver = resolver.namespace_dict[ns]

During handling of the above exception ('

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\core\handlers\exception.py" in inner 34. response = get_response(request)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\core\handlers\base.py" in _get_response 145. response = self.process_exception_by_middleware(e, request)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\core\handlers\base.py" in _get_response 143. response = response.render()

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\response.py" in render 106. self.content = self.rendered_content

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\response.py" in rendered_content 83. content = template.render(context, self._request)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\backends\django.py" in render 61. return self.template.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render 171. return self._render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in _render 163. return self.nodelist.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render 937. bit = node.render_annotated(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render_annotated 904. return self.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\loader_tags.py" in render 150. return compiled_parent._render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in _render 163. return self.nodelist.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render 937. bit = node.render_annotated(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render_annotated 904. return self.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\loader_tags.py" in render 150. return compiled_parent._render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in _render 163. return self.nodelist.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render 937. bit = node.render_annotated(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render_annotated 904. return self.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\loader_tags.py" in render 62. result = block.nodelist.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render 937. bit = node.render_annotated(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render_annotated 904. return self.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\loader_tags.py" in render 62. result = block.nodelist.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render 937. bit = node.render_annotated(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render_annotated 904. return self.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\defaulttags.py" in render 309. return nodelist.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render 937. bit = node.render_annotated(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\base.py" in render_annotated 904. return self.render(context)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\template\defaulttags.py" in render 443. url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

File "C:\Users\User\Anaconda3\envs\simplesocialenv\lib\site-packages\django\urls\base.py" in reverse 86. raise NoReverseMatch("%s is not a registered namespace" % key)

Exception Type: NoReverseMatch at /groups/ Exception Value: '

And here is my related source code:

project.urls.py

from django.contrib import admin
from django.urls import path, include
from . import views


urlpatterns = [
    path('accounts/', include('accounts.urls', namespace='accounts')),
    path('groups/', include('groups.urls', namespace='groups')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('admin/', admin.site.urls),
    path('', views.HomePage.as_view(), name='home'),
    path('test/', views.TestPage.as_view(), name='test'),
    path('thanks/', views.ThanksPage.as_view(), name='thanks'),
    path('posts/', include('posts.urls'), name='posts'),
]

projects settings.py file

INSTALLED_APPS = [
    'groups',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bootstrap3',
    'accounts',
    'posts',
]

groups.urls.py file

# GROUPS URLS.PY
from django.urls import path, include, re_path
from . import views

app_name = 'groups'

urlpatterns = [
    path('', views.ListGroups.as_view(), name='all'),
    path('new/', views.CreateGroup.as_view(), name='create'),
    # re_path(r'posts/in/(?P<slug>[-\w]+)/$', views.SingleGroup.as_view(), name='single'),
    path('posts/in/<slug:slug>/', views.SingleGroup.as_view(), name='single'),
    path('join/<slug>/', views.JoinGroup.as_view(), name='join'),
    path('leave/<slug>/', views.JoinGroup.as_view(), name='leave')
]

groups/views.py file

from django.shortcuts import render, get_object_or_404
from django.contrib.auth.mixins import (LoginRequiredMixin,
                                        PermissionRequiredMixin)
from django.contrib import messages
from django.urls import reverse
from django.views import generic
from groups.models import Group, GroupMember

class CreateGroup(LoginRequiredMixin, generic.CreateView):
    fields = ('name', 'description')
    model = Group

class SingleGroup(generic.DetailView):
    model = Group

class ListGroups(generic.ListView):
    model = Group


class JoinGroup(LoginRequiredMixin, generic.RedirectView):

    def get_redirect_url(self, *args, **kwargs):
        return reverse('groups:single', kwargs={'slug':self.kwargs.get('slug')})

    def get(self, request, *args, **kwargs):
        group = get_object_or_404(Group, slug=self.kwargs.get('slug'))

        try:
            GroupMember.objects.create(user=self.request.user, group=group)
        except IntegrityError:
            messages.warning(self.request, ('Warning already a member'))
        else:
            messages.success(self.request, ('You are now a member'))
        return super().get(request, *args, **kwargs)

class LeaveGroup(LoginRequiredMixin, generic.RedirectView):

    def get_redirect_url(self, *args, **kwargs):
        return reverse('groups:single', kwargs={'slug':self.kwargs.get('slug')})

    def get(self, request, *args, **kwargs):
        try:
            membership = models.GroupMember.objects.filter(
            user=self.request.user,
            group__slug=self.kwargs.get('slug')
            ).get()
        except models.GroupMember.DoesNotExist:
            messages.warning(self.request, 'sorry you are not in this group')
        else:
            membership.delete()
            messages.success(self.request, 'You have left the group')
            return super().get(request, *args, *kwargs)
1
the issue is with your template file. there is most probably a typo there. please add it also to the question.Abhyudai
Yes. I’ve figured out that one of my templates calling contains a typo like { % url ‘<groups:xxx’ %}Quantes

1 Answers

1
votes

Two things maybe:

  • groups does not appear in your INSTALLED_APPS parameter, is that normal?
  • regarding your error log, it seems like you've got a typo in your template calling for /groups/. Check if you have the good quote type, and that also they are closed.