NoReverseMatch at , I have Recently a class from one app and added it to a new app and I revised everything but keep receiving this Error, what did i miss?

56 views
Skip to first unread message

Ahmed Khairy

unread,
Apr 24, 2020, 11:29:41 PM4/24/20
to Django users
I have created a new app in a project and moved one of the classes from one app to the new app 

I checked every step but I keep getting No Reverse match I wrote the name of the app before the namespace but still 


HTML : 
 
 <a class="nav-link waves-effect" href="{% url 'score:post-create' %}" > Upload Designs </a>



URLS 
from django.urls import include, path

from . import views
from .views import (PostCreateView, PostDeleteView, PostDetailView,
                    PostListView, PostUpdateView, UserPostListView)

app_name = 'score'

urlpatterns = [
    path('user/<str:username>', UserPostListView.as_view(), name='user-posts'),
    path('score/', PostListView.as_view(), name='score'),
    path('score/<int:pk>/', PostDetailView.as_view(), name='post-detail'),
    path('score/new/'include(('post-create.urls''post-create'), PostCreateView.as_view(), name='post-create'),
    path('score/<int:pk>/update/', PostUpdateView.as_view(), name='post-update'),
    path('score/<int:pk>/delete/', PostDeleteView.as_view(), name='post-delete')
]


settings:
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import include, path

from users import views as user_views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/'include('allauth.urls')),
    path(''include('core.urls'namespace='core')),
    path('register/', user_views.register, name='register'),
    path('profile/', user_views.profile, name='profile'),

views
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.models import User
from django.contrib.messages.views import SuccessMessageMixin
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone
from django.views.generic import (
    CreateView, DeleteView, DetailView, ListView, UpdateView)

from .models import Post



class PostListView(ListView):
    model = Post
    template_name = "score.html"
    context_object_name = 'posts'

class PostCreateView(LoginRequiredMixin, SuccessMessageMixin, CreateView):
    model = Post
    fields = ['caption''design']
    template_name = "score/post_form.html"

    def form_valid(selfform):
        form.instance.author = self.request.user
        return super().form_valid(form)

models

from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.shortcuts import reverse
from django.utils import timezone


# Create your models here.
class Post(models.Model):
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    design = models.ImageField(
        blank=Falsenull=Trueupload_to='new designs')

    def __str__(self):
        return self.caption

    def get_absolute_url(self):
        return reverse("score:post-detail"kwargs={"pk"self.pk})




Motaz Hejaze

unread,
Apr 24, 2020, 11:33:48 PM4/24/20
to Django users
path('score/new/'include(('post-create.urls''post-create'), PostCreateView.as_view(), name='post-create'),

explain this line ?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a5bf9872-8877-42dd-b76b-cfd1cd316ef5%40googlegroups.com.

Ahmed Khairy

unread,
Apr 24, 2020, 11:39:10 PM4/24/20
to Django users
I was trying to include the urls

originally it was 

    path('score/new/', PostCreateView.as_view(), name='post-create'),

but still both not working 
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Ahmed Khairy

unread,
Apr 25, 2020, 12:16:09 AM4/25/20
to Django users
I tried to include the urls 

originally it was 

    path('score/new/', PostCreateView.as_view(), name='post-create'),

but both didn't work 

Motaz Hejaze

unread,
Apr 25, 2020, 12:30:53 AM4/25/20
to Django users
you don't need the include part because you already copied the class to the new app

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c813a663-e0dc-447e-94a9-a5dda31b3ac6%40googlegroups.com.

Motaz Hejaze

unread,
Apr 25, 2020, 12:31:30 AM4/25/20
to Django users
did you add your new app to installed apps in settings.py

Ahmed Khairy

unread,
Apr 25, 2020, 12:34:42 AM4/25/20
to Django users
yes 

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'users.apps.UsersConfig',
    'core',
    'crispy_forms',
    'django_filters',
    'score'
]


On Saturday, April 25, 2020 at 12:31:30 AM UTC-4, Motaz Hejaze wrote:
did you add your new app to installed apps in settings.py

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Motaz Hejaze

unread,
Apr 25, 2020, 12:42:14 AM4/25/20
to Django users
did you try to change the name 'post-create' to something else ?

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0bd12de7-9b6d-4a56-9ea1-d8ba11c6f192%40googlegroups.com.

Ahmed Khairy

unread,
Apr 25, 2020, 1:13:08 AM4/25/20
to Django users
Yes i tried other urls from other models it worked but anything related to the new app is not linked

Ahmed Khairy

unread,
Apr 25, 2020, 1:28:19 AM4/25/20
to Django users
I added the new app urls to the main project URLs I think this was the mistake but now I have to change the URLs location as I'm getting 404 error score/score/

Thank you,  your first question is what made me find the issue

maninder singh Kumar

unread,
Apr 25, 2020, 11:24:59 AM4/25/20
to django...@googlegroups.com
A URL.py problem
Reg
Willy

Sent from my iPad
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0bd12de7-9b6d-4a56-9ea1-d8ba11c6f192%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages