Why getting 'reverse match error' when moving template files relating to specific app to master template folder










0














I am new to Django. I have found many links matching to this problem, but I did not understand them.
I am creating blog app. Everything was working fine, until I created another app called 'services', and created separate template folders for 'blog', 'services' and 'master'. Now, when I click on 'create new post' in blog app, I get 'Reverse for 'post_publish' with keyword arguments ''pk': ''' not found. 1 pattern(s) tried: ['blog/post/(?P[0-9]+)/publish/$']'
Please help me, I do not understand what that error is trying to tell.



Blog_views.py



from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from blog.models import Post, Comment
from django.utils import timezone
from blog.forms import PostForm, CommentForm
from django.views.generic import (TemplateView,ListView,
DetailView,CreateView,
UpdateView,DeleteView)
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.text import slugify

# Create your views here.

class PostListView(ListView):
model = Post
template_name ="blog/blog/post_list.html"

def get_queryset(self):
return Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')


class PostDetailView(DetailView):
model = Post
template_name ="blog/blog/post_detail.html"


class CreatePostView(LoginRequiredMixin,CreateView):
login_url = '/login/'
template_name ="blog/blog/post_detail.html"
redirect_field_name = 'blog/blog/post_form.html'

form_class = PostForm
model = Post
# template_name ="blog/blog/post_detail.html"


class PostUpdateView(LoginRequiredMixin,UpdateView):
login_url = '/login/'
redirect_field_name = 'blog/blog/post_detail.html'

form_class = PostForm

model = Post


class DraftListView(LoginRequiredMixin,ListView):
login_url = '/login/'
redirect_field_name = 'blog/blog/post_list.html'

model = Post

def get_queryset(self):
return Post.objects.filter(published_date__isnull=True).order_by('created_date')


class PostDeleteView(LoginRequiredMixin,DeleteView):
model = Post
success_url = reverse_lazy('blog:post_list')

#######################################
## Functions that require a pk match ##
#######################################
@login_required
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
return redirect('blog:post_detail', slug=post.slug)

# @login_required
def add_comment_to_post(request, pk):
post = get_object_or_404(Post, pk=pk)
if request.method == "POST":
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.save()
return redirect('blog:post_detail', slug=post.slug)
else:
form = CommentForm()
return render(request, 'blog/blog/comment_form.html', 'form': form)


@login_required
def comment_approve(request, pk):
comment = get_object_or_404(Comment, pk=pk)
comment.approve()
return redirect('blog:post_detail', slug=comment.post.slug)


@login_required
def comment_remove(request, pk):
comment = get_object_or_404(Comment, pk=pk)
post_pk = comment.post.pk
comment.delete()
return redirect('blog:post_detail', pk=post_pk)


main_urls.py



from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views
from django.conf.urls.static import static
from django.conf import settings
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('about/', views.AboutView.as_view(), name='about'),
path('blog/', include('blog.urls', namespace="blog")),
path('services/', include('services.urls', namespace="services")),
path('accounts/', include('django.contrib.auth.urls')),
path('ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)


blog_urls.py



from django.urls import path, re_path
from . import views

app_name = 'blog'

urlpatterns = [
path('', views.PostListView.as_view(), name='post_list'),
# path('about/', views.AboutView.as_view(), name='about'),
path('post/<slug>', views.PostDetailView.as_view(), name='post_detail'),
path('post/new/', views.CreatePostView.as_view(), name='post_new'),
path('post/<int:pk>/edit/', views.PostUpdateView.as_view(), name='post_edit'),
path('drafts/', views.DraftListView.as_view(), name='post_draft_list'),
path('post/<int:pk>/remove/', views.PostDeleteView.as_view(), name='post_remove'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
path('post/<int:pk>/comment/', views.add_comment_to_post, name='add_comment_to_post'),
path('comment/<int:pk>/approve/', views.comment_approve, name='comment_approve'),
path('comment/<int:pk>/remove/', views.comment_remove, name='comment_remove'),
]


Error page attached










share|improve this question























  • Could you please show us your template (the one with the url which cannot be resolved).
    – mistiru
    Nov 14 '18 at 13:31















0














I am new to Django. I have found many links matching to this problem, but I did not understand them.
I am creating blog app. Everything was working fine, until I created another app called 'services', and created separate template folders for 'blog', 'services' and 'master'. Now, when I click on 'create new post' in blog app, I get 'Reverse for 'post_publish' with keyword arguments ''pk': ''' not found. 1 pattern(s) tried: ['blog/post/(?P[0-9]+)/publish/$']'
Please help me, I do not understand what that error is trying to tell.



Blog_views.py



from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from blog.models import Post, Comment
from django.utils import timezone
from blog.forms import PostForm, CommentForm
from django.views.generic import (TemplateView,ListView,
DetailView,CreateView,
UpdateView,DeleteView)
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.text import slugify

# Create your views here.

class PostListView(ListView):
model = Post
template_name ="blog/blog/post_list.html"

def get_queryset(self):
return Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')


class PostDetailView(DetailView):
model = Post
template_name ="blog/blog/post_detail.html"


class CreatePostView(LoginRequiredMixin,CreateView):
login_url = '/login/'
template_name ="blog/blog/post_detail.html"
redirect_field_name = 'blog/blog/post_form.html'

form_class = PostForm
model = Post
# template_name ="blog/blog/post_detail.html"


class PostUpdateView(LoginRequiredMixin,UpdateView):
login_url = '/login/'
redirect_field_name = 'blog/blog/post_detail.html'

form_class = PostForm

model = Post


class DraftListView(LoginRequiredMixin,ListView):
login_url = '/login/'
redirect_field_name = 'blog/blog/post_list.html'

model = Post

def get_queryset(self):
return Post.objects.filter(published_date__isnull=True).order_by('created_date')


class PostDeleteView(LoginRequiredMixin,DeleteView):
model = Post
success_url = reverse_lazy('blog:post_list')

#######################################
## Functions that require a pk match ##
#######################################
@login_required
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
return redirect('blog:post_detail', slug=post.slug)

# @login_required
def add_comment_to_post(request, pk):
post = get_object_or_404(Post, pk=pk)
if request.method == "POST":
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.save()
return redirect('blog:post_detail', slug=post.slug)
else:
form = CommentForm()
return render(request, 'blog/blog/comment_form.html', 'form': form)


@login_required
def comment_approve(request, pk):
comment = get_object_or_404(Comment, pk=pk)
comment.approve()
return redirect('blog:post_detail', slug=comment.post.slug)


@login_required
def comment_remove(request, pk):
comment = get_object_or_404(Comment, pk=pk)
post_pk = comment.post.pk
comment.delete()
return redirect('blog:post_detail', pk=post_pk)


main_urls.py



from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views
from django.conf.urls.static import static
from django.conf import settings
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('about/', views.AboutView.as_view(), name='about'),
path('blog/', include('blog.urls', namespace="blog")),
path('services/', include('services.urls', namespace="services")),
path('accounts/', include('django.contrib.auth.urls')),
path('ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)


blog_urls.py



from django.urls import path, re_path
from . import views

app_name = 'blog'

urlpatterns = [
path('', views.PostListView.as_view(), name='post_list'),
# path('about/', views.AboutView.as_view(), name='about'),
path('post/<slug>', views.PostDetailView.as_view(), name='post_detail'),
path('post/new/', views.CreatePostView.as_view(), name='post_new'),
path('post/<int:pk>/edit/', views.PostUpdateView.as_view(), name='post_edit'),
path('drafts/', views.DraftListView.as_view(), name='post_draft_list'),
path('post/<int:pk>/remove/', views.PostDeleteView.as_view(), name='post_remove'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
path('post/<int:pk>/comment/', views.add_comment_to_post, name='add_comment_to_post'),
path('comment/<int:pk>/approve/', views.comment_approve, name='comment_approve'),
path('comment/<int:pk>/remove/', views.comment_remove, name='comment_remove'),
]


Error page attached










share|improve this question























  • Could you please show us your template (the one with the url which cannot be resolved).
    – mistiru
    Nov 14 '18 at 13:31













0












0








0







I am new to Django. I have found many links matching to this problem, but I did not understand them.
I am creating blog app. Everything was working fine, until I created another app called 'services', and created separate template folders for 'blog', 'services' and 'master'. Now, when I click on 'create new post' in blog app, I get 'Reverse for 'post_publish' with keyword arguments ''pk': ''' not found. 1 pattern(s) tried: ['blog/post/(?P[0-9]+)/publish/$']'
Please help me, I do not understand what that error is trying to tell.



Blog_views.py



from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from blog.models import Post, Comment
from django.utils import timezone
from blog.forms import PostForm, CommentForm
from django.views.generic import (TemplateView,ListView,
DetailView,CreateView,
UpdateView,DeleteView)
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.text import slugify

# Create your views here.

class PostListView(ListView):
model = Post
template_name ="blog/blog/post_list.html"

def get_queryset(self):
return Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')


class PostDetailView(DetailView):
model = Post
template_name ="blog/blog/post_detail.html"


class CreatePostView(LoginRequiredMixin,CreateView):
login_url = '/login/'
template_name ="blog/blog/post_detail.html"
redirect_field_name = 'blog/blog/post_form.html'

form_class = PostForm
model = Post
# template_name ="blog/blog/post_detail.html"


class PostUpdateView(LoginRequiredMixin,UpdateView):
login_url = '/login/'
redirect_field_name = 'blog/blog/post_detail.html'

form_class = PostForm

model = Post


class DraftListView(LoginRequiredMixin,ListView):
login_url = '/login/'
redirect_field_name = 'blog/blog/post_list.html'

model = Post

def get_queryset(self):
return Post.objects.filter(published_date__isnull=True).order_by('created_date')


class PostDeleteView(LoginRequiredMixin,DeleteView):
model = Post
success_url = reverse_lazy('blog:post_list')

#######################################
## Functions that require a pk match ##
#######################################
@login_required
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
return redirect('blog:post_detail', slug=post.slug)

# @login_required
def add_comment_to_post(request, pk):
post = get_object_or_404(Post, pk=pk)
if request.method == "POST":
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.save()
return redirect('blog:post_detail', slug=post.slug)
else:
form = CommentForm()
return render(request, 'blog/blog/comment_form.html', 'form': form)


@login_required
def comment_approve(request, pk):
comment = get_object_or_404(Comment, pk=pk)
comment.approve()
return redirect('blog:post_detail', slug=comment.post.slug)


@login_required
def comment_remove(request, pk):
comment = get_object_or_404(Comment, pk=pk)
post_pk = comment.post.pk
comment.delete()
return redirect('blog:post_detail', pk=post_pk)


main_urls.py



from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views
from django.conf.urls.static import static
from django.conf import settings
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('about/', views.AboutView.as_view(), name='about'),
path('blog/', include('blog.urls', namespace="blog")),
path('services/', include('services.urls', namespace="services")),
path('accounts/', include('django.contrib.auth.urls')),
path('ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)


blog_urls.py



from django.urls import path, re_path
from . import views

app_name = 'blog'

urlpatterns = [
path('', views.PostListView.as_view(), name='post_list'),
# path('about/', views.AboutView.as_view(), name='about'),
path('post/<slug>', views.PostDetailView.as_view(), name='post_detail'),
path('post/new/', views.CreatePostView.as_view(), name='post_new'),
path('post/<int:pk>/edit/', views.PostUpdateView.as_view(), name='post_edit'),
path('drafts/', views.DraftListView.as_view(), name='post_draft_list'),
path('post/<int:pk>/remove/', views.PostDeleteView.as_view(), name='post_remove'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
path('post/<int:pk>/comment/', views.add_comment_to_post, name='add_comment_to_post'),
path('comment/<int:pk>/approve/', views.comment_approve, name='comment_approve'),
path('comment/<int:pk>/remove/', views.comment_remove, name='comment_remove'),
]


Error page attached










share|improve this question















I am new to Django. I have found many links matching to this problem, but I did not understand them.
I am creating blog app. Everything was working fine, until I created another app called 'services', and created separate template folders for 'blog', 'services' and 'master'. Now, when I click on 'create new post' in blog app, I get 'Reverse for 'post_publish' with keyword arguments ''pk': ''' not found. 1 pattern(s) tried: ['blog/post/(?P[0-9]+)/publish/$']'
Please help me, I do not understand what that error is trying to tell.



Blog_views.py



from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from blog.models import Post, Comment
from django.utils import timezone
from blog.forms import PostForm, CommentForm
from django.views.generic import (TemplateView,ListView,
DetailView,CreateView,
UpdateView,DeleteView)
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.text import slugify

# Create your views here.

class PostListView(ListView):
model = Post
template_name ="blog/blog/post_list.html"

def get_queryset(self):
return Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')


class PostDetailView(DetailView):
model = Post
template_name ="blog/blog/post_detail.html"


class CreatePostView(LoginRequiredMixin,CreateView):
login_url = '/login/'
template_name ="blog/blog/post_detail.html"
redirect_field_name = 'blog/blog/post_form.html'

form_class = PostForm
model = Post
# template_name ="blog/blog/post_detail.html"


class PostUpdateView(LoginRequiredMixin,UpdateView):
login_url = '/login/'
redirect_field_name = 'blog/blog/post_detail.html'

form_class = PostForm

model = Post


class DraftListView(LoginRequiredMixin,ListView):
login_url = '/login/'
redirect_field_name = 'blog/blog/post_list.html'

model = Post

def get_queryset(self):
return Post.objects.filter(published_date__isnull=True).order_by('created_date')


class PostDeleteView(LoginRequiredMixin,DeleteView):
model = Post
success_url = reverse_lazy('blog:post_list')

#######################################
## Functions that require a pk match ##
#######################################
@login_required
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
return redirect('blog:post_detail', slug=post.slug)

# @login_required
def add_comment_to_post(request, pk):
post = get_object_or_404(Post, pk=pk)
if request.method == "POST":
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.save()
return redirect('blog:post_detail', slug=post.slug)
else:
form = CommentForm()
return render(request, 'blog/blog/comment_form.html', 'form': form)


@login_required
def comment_approve(request, pk):
comment = get_object_or_404(Comment, pk=pk)
comment.approve()
return redirect('blog:post_detail', slug=comment.post.slug)


@login_required
def comment_remove(request, pk):
comment = get_object_or_404(Comment, pk=pk)
post_pk = comment.post.pk
comment.delete()
return redirect('blog:post_detail', pk=post_pk)


main_urls.py



from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views
from django.conf.urls.static import static
from django.conf import settings
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('about/', views.AboutView.as_view(), name='about'),
path('blog/', include('blog.urls', namespace="blog")),
path('services/', include('services.urls', namespace="services")),
path('accounts/', include('django.contrib.auth.urls')),
path('ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)


blog_urls.py



from django.urls import path, re_path
from . import views

app_name = 'blog'

urlpatterns = [
path('', views.PostListView.as_view(), name='post_list'),
# path('about/', views.AboutView.as_view(), name='about'),
path('post/<slug>', views.PostDetailView.as_view(), name='post_detail'),
path('post/new/', views.CreatePostView.as_view(), name='post_new'),
path('post/<int:pk>/edit/', views.PostUpdateView.as_view(), name='post_edit'),
path('drafts/', views.DraftListView.as_view(), name='post_draft_list'),
path('post/<int:pk>/remove/', views.PostDeleteView.as_view(), name='post_remove'),
path('post/<int:pk>/publish/', views.post_publish, name='post_publish'),
path('post/<int:pk>/comment/', views.add_comment_to_post, name='add_comment_to_post'),
path('comment/<int:pk>/approve/', views.comment_approve, name='comment_approve'),
path('comment/<int:pk>/remove/', views.comment_remove, name='comment_remove'),
]


Error page attached







django






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 7:33







CA Ankit Sharma

















asked Nov 13 '18 at 5:46









CA Ankit SharmaCA Ankit Sharma

11




11











  • Could you please show us your template (the one with the url which cannot be resolved).
    – mistiru
    Nov 14 '18 at 13:31
















  • Could you please show us your template (the one with the url which cannot be resolved).
    – mistiru
    Nov 14 '18 at 13:31















Could you please show us your template (the one with the url which cannot be resolved).
– mistiru
Nov 14 '18 at 13:31




Could you please show us your template (the one with the url which cannot be resolved).
– mistiru
Nov 14 '18 at 13:31












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274572%2fwhy-getting-reverse-match-error-when-moving-template-files-relating-to-specifi%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274572%2fwhy-getting-reverse-match-error-when-moving-template-files-relating-to-specifi%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党