If you are not authorized, then everything will work fine, as soon as
you authorize, for example, adeline, this error will be issued, I do
not know what happened!
NoReverseMatch at /series/Colony/Season_1/Episode_1/
Reverse for 'post_of_serie' with no arguments not found. 1 pattern(s) tried: ['series/(?P<serial_slug>[\\w-]+)/(?P<season_slug>[\\w-]+)/(?P<series_slug>[\\w-]+)/$']
main urls.py
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^series/', include("serials.urls", namespace='series')),
url(r'^', include("serials.urls", namespace='homeview')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
second urls.py to app(series)
from django.conf.urls import include, url
from .views import homeview, post_of_serial, post_of_season, post_of_serie, validate_email, mark_and_unmark_this_episode
urlpatterns = [
url(r'^$', homeview, name='homeview'),
url(r'^subscribe/$', validate_email, name='subscribe'), # /series/
url(r'^mark_or_unmark_this_episode/$', mark_and_unmark_this_episode, name="mark_and_unmark_this_episode"),
url(r'^(?P<serial_slug>[\w-]+)/$', post_of_serial, name='post_of_serial'), # /series/Prison_Break/
url(r'^(?P<serial_slug>[\w-]+)/(?P<season_slug>[\w-]+)/$', post_of_season, name='post_of_season'), # /series/Prison_Break/season_5/
url(r'^(?P<serial_slug>[\w-]+)/(?P<season_slug>[\w-]+)/(?P<series_slug>[\w-]+)/$', post_of_serie, name='post_of_serie'), # /series/Prison_Break/season_5/2/
]
error
this is part of view.py
def post_of_serie(request, serial_slug=None, season_slug=None, series_slug=None):
serie = get_object_or_404(Series, serial_of_this_series__slug=serial_slug, season_of_this_series__slug=season_slug, slug=series_slug)
#print(serie)
title = serie.serial_of_this_series.rus_name_of_seriall
full_path = All_Images_Of_The_Series.objects.filter(to_series__serial_of_this_series__slug=serial_slug, to_series__season_of_this_series__slug=season_slug, to_series__slug=series_slug, is_poster=True)
context = {"serie":serie, "full_path":full_path, "title":title,}
try:
userr = request.user
check_button = watched_series.objects.filter(user=request.user, watched_serial__slug=serial_slug, watched_serie__season_of_this_series__slug=season_slug, watched_serie__slug=series_slug )
context["check_button"] = check_button
context["userr"] = userr
except:
pass
return render(request, 'series.html', context)
if delete somethig in views.py nothing change!!!
main html
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>{{ title }}</title>
<!-- Bootstrap -->
<link href="{% static "css/bootstrap.min.css"%}" rel="stylesheet">
<link href="{% static "css/footer.css"%}" rel="stylesheet">
<link href="{% static "css/main.css"%}" rel="stylesheet">
{% block styles %}{% endblock styles %}
</head>
<body>
<div class="advertises" ></div>
<div class="wrapper">
<div class="wrapper-content">
{% include "navbar.html" %}
{% block content %}
{% endblock content %}
</div>
{% include "footer.html" %}
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="{% static "js/bootstrap.min.js"%}"></script>
<script src="{% static "js/smooth-scroll.js"%}"></script>
<script src="{% static "js/script.js" %}"></script>
</body>
</html>
series.html where is up error!
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<div class="container">
<div class="row">
<div class="col-sm-8 her">
<span class="links" >
<a class="a-link" href="{{ serie.serial_of_this_series.get_absolute_url }}">{{ serie.serial_of_this_series.rus_name_of_seriall }} <img src="{% static "img/breadcrumbs-arrow.png" %}" class="arrow" > </a>
<a class="a-link" href="{{ serie.season_of_this_series.get_absolute_url }}">{{ serie.season_of_this_series.name_of_the_season }}<img src="{% static "img/breadcrumbs-arrow.png" %}" class="arrow" ></a>
<a class="a-link" href="{{ serie.get_absolute_url }}">{{ serie.rus_name }}<img src="{% static "img/breadcrumbs-arrow.png" %}" class="arrow" ></a>
</span>
<div class="title-block" >
<h3 class="seria-header">
<img src="{{ serie.serial_of_this_series.preview_of_serial.url }}" class="thumb">
<span class="titles" >
<div class="title-ru">{{ serie.rus_name }}</div>
<div class="title-en">{{ serie.eng_name }}</div>
</span>
</h3>
{% if user.is_authenticated %}
<form class="watch_button" method="POST" action="{% url 'series:post_of_serie' %}" > {% csrf_token %}
<div class="buttons" >
<div class="second_section_of_buttons" >
{% if check_button %}
<div class="isawthat-btn checcked" title="Серия просмотрена. Убрать пометку?" ><img src="{% static "img/white-eye-icon.png" %}" class="iccon"/><span class="text_button" >Серия просмотрена</span></div>
{% else %}
<div class="isawthat-btn" title="Пометить серию как просмотренную" ><img src="{% static "img/pink-eye-icon.png" %}" class="iccon"/><span class="text_button" >Серия Не просмотрена</span></div>
</div>
{% endif %}
</div>
<p class="user hidden" >{{ userr }}</p>
<p class="watched_serial hidden" >{{ serie.serial_of_this_series }}</p>
<p class="watched_serie hidden" >{{ serie }}</p>
<p class="minutes_of_series hidden" >{{ serie }}</p>
<p class="serial_slug hidden" > {{ serie.serial_of_this_series.slug }} </p>
<p class="season_slug hidden" > {{ serie.season_of_this_series.slug }} </p>
<p class="series_slug hidden" > {{ serie.slug }} </p>
</form>
{% endif %}
</div>
</div>
<div class="col-sm-3">
</div>
</div>
</div>
{% endblock content %}
<form class="watch_button" method="POST" action="{% url 'series:post_of_serie' %}" >
this is the line you are having the error bro, see, this form appears only for logged in user, and you dont have a view like def post_of_serie(request):
try to pass the slugs here in the form url, then the problem will be solved
Related
I am trying to use django-views-breadcrumbs to add breadcrumbs to a site. I can get it to work with some views but I am getting an error with a particular listview. When I attempt to visit this listview page I see the error.
The error appears to be related to a need for the correct context. So far I have not been able to figure this out.
The error:
NoReverseMatch at /projects/project/1/notes/
Reverse for 'projectnotes_list' with no arguments not found. 1 pattern(s) tried: ['projects/project/(?P<pk>[0-9]+)/notes/\\Z']
Request Method: GET
Request URL: http://co1.localhost:8000/projects/project/1/notes/
Django Version: 3.1.14
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'projectnotes_list' with no arguments not found. 1 pattern(s) tried: ['projects/project/(?P<pk>[0-9]+)/notes/\\Z']
Exception Location: /Users/user/.local/share/virtualenvs/osite-wGphEfbP/lib/python3.9/site-packages/django/urls/resolvers.py, line 689, in _reverse_with_prefix
Python Executable: /Users/user/.local/share/virtualenvs/osite-wGphEfbP/bin/python
Python Version: 3.9.6
Python Path:
['/Users/user/Desktop/otools',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
'/Users/user/.local/share/virtualenvs/osite-wGphEfbP/lib/python3.9/site-packages']
Server time: Sun, 20 Feb 2022 15:52:17 +0000
The list view:
class ProjectNotesList(ListBreadcrumbMixin,ListView):
model = ProjectNotes
template_name = 'company_accounts/project_notes.html'
comments = ProjectNotes.comments
def related_project(self, **kwargs):
project = get_object_or_404(Project, id=self.kwargs.get('pk'))
notes = ProjectNotes.objects.all
return notes
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
context['project'] = get_object_or_404(Project, id=self.kwargs.get('pk'))
return context
commentscount = ProjectNotes.objects.annotate(num_comments=Count('comments'))
The urls.py
from django.urls import path, include
from .views import CompanyProjects, CompanyProjectsDetailView, TodoCreateView, ProjectNotesList, ProjectNotesCreateView, ProjectCreateView, ProjectNotesDetailView, CompanyCompletedProjects, CompanyPausedProjects, TodosList, ProjectTodosDetailView, ProjectDocumentsList, ProjectDocumentsCreateView, ProjectDocumentsDetailView
from . import views
app_name = 'company_project'
urlpatterns = [
path('', CompanyProjects.as_view(), name='project_list'),
path('completed_projects', CompanyCompletedProjects.as_view(), name='completed_projects'),
path('paused_projects', CompanyPausedProjects.as_view(), name='paused_projects'),
path('add_project/', ProjectCreateView.as_view(), name='add_project'),
path('project/<int:pk>/', CompanyProjectsDetailView.as_view(), name='project_detail'),
path('project/<int:pk>/todos/', TodosList.as_view(), name='project_todos'),
path('project/<int:project_pk>/todo/<int:pk>/', ProjectTodosDetailView.as_view(), name='project_todo_detail'),
path('project/<int:pk>/add_todo/', TodoCreateView.as_view(), name='add_todo'),
path('project/<int:pk>/add_project_note/', ProjectNotesCreateView.as_view(), name='add_project_note'),
path('project/<int:pk>/notes/', ProjectNotesList.as_view(), name='projectnotes_list'),
#path('note/<int:pk>/add_project_note_comment/', ProjectNotesCommentCreateView.as_view(),
# name='add_project_note_comment'),
path('project/<int:project_pk>/note/<int:pk>/', ProjectNotesDetailView.as_view(), name='project_note_detail'),
path('project/<int:pk>/documents/', ProjectDocumentsList.as_view(), name='project_documents'),
path('project/<int:pk>/add_project_document/', ProjectDocumentsCreateView.as_view(), name='add_project_document'),
path('project/<int:project_pk>/document/<int:pk>/', ProjectDocumentsDetailView.as_view(), name='project_document_detail'),
]
The base and page templates:
base
<!DOCTYPE html>
{% load static %}
{% load view_breadcrumbs %}
<html>
<head>
<meta charset="utf-8">
<title>{% block title %}Site{% endblock title %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link type="text/x-scss" href="{% static 'bootstrap/scss/bootstrap.scss' %}" rel="stylesheet" media="screen">
<!-- Custom CSS -->
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}"/>
<link rel="shortcut icon" type="image/png" href="{% static 'core_images/OH_favicon.png' %}"/>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-VJRXH7YFXZ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-VJRXH7YFXZ');
</script>
</head>
<body>
<wrapper class="d-flex flex-column">
{% include 'nav.html' %}
<main class="flex-fill">
<div class="row">
<div class="col-12">
<br />
{% block breadcrumbs %}
{% render_breadcrumbs 'view_breadcrumbs/bootstrap4.html' %}
{% endblock breadcrumbs %}
{% block messages %}{% endblock messages %}
</div>
</div>
{% block content %}
<h1>Hello</h1>
{% endblock content %}
</main>
{% include 'footer.html' %}
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</wrapper>
</body>
</html>
page
<!-- templates/company_accounts/project_notes.html -->
{% extends 'base.html' %}
{% block content %}
<div class="section-container container">
<div class="general-section-header">
<div class="header-add-new">
<a class="btn btn-success" href="{% url 'company_project:add_project_note' project.pk %}" role="button">Add Note</a>
</div>
<h1>Notes for {{ project }}</h1>
</div>
{% if project.notes.all %}
{% for note in project.notes.all %}
<div class ="projectnotes-entry">
<div class="col-sm-8">
<div class="row-sm-6">
<div class="card mb-2">
<div class="card-body">
<div class="card-title">{{ note.title }}</div>
<div class="card-text">{{ note.body | safe | truncatewords:"20"|linebreaks }}
<div>{{ note.comments.all.count }} comments</div>
read more</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p>No notes have been have been added yet.</p>
{% endif %}
</div>
{% endblock content %}
There is a demo included with the breadcrumb app the provides some insight. However I have not been able to figure out how to add necessaryt context using code from the demo.
The demo code:
class TestListsView(ListBreadcrumbMixin, ListView):
model = TestModel
template_name = "demo/test-list.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
view_paths = []
for instance in self.object_list:
view_paths.append(
(
instance.name,
detail_instance_view_url(instance),
),
)
context["view_paths"] = view_paths
return context
I m working on learning Django with MDN project on Local Library.
My two pages are rendering whereas the book detail page is not rendering and giving error page not found. Please advice what if I have missed anything:
So far entire project is on MDN documents.
catalog/urls.py
from django.urls import path
from catalog import views
app_name = 'catalog'
urlpatterns = [
path('', views.index, name='index'),
path('books/', views.BookListView.as_view(), name='books'),
path('book/<int:pk>', views.BookDetailView.as_view(), name='book-detail'),
]
catalog/templates/catalog/book_detail.html
{% extends 'catalog/base.html' %}
{% block content %}
<h1>Title: {{ book.title }}</h1>
<p><strong>Author:</strong> {{ book.author }}</p>
<p><strong>Summary:</strong> {{ book.summary }}</p>
<p><strong>ISBN:</strong> {{ book.isbn }}</p>
<p><strong>Language:</strong> {{ book.language }}</p>
<p><strong>Genre:</strong> {{ book.genre.all|join:", " }}</p>
<div style="margin-left:20px;margin-top:20px">
<h4>Copies</h4>
{% for copy in book.bookinstance_set.all %}
<hr>
<p class="{% if copy.status == 'a' %}text-success{% elif copy.status == 'd' %}text-danger{% else %}text-warning{% endif %}">{{ copy.get_status_display }}</p>
{% if copy.status != 'a' %}<p><strong>Due to be returned:</strong> {{copy.due_back}}</p>{% endif %}
<p><strong>Imprint:</strong> {{copy.imprint}}</p>
<p class="text-muted"><strong>Id:</strong> {{copy.id}}</p>
{% endfor %}
</div>
{% endblock %}
catalog/templates/catalog/base.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="{% static 'catalog/style.css' %}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous"/>
{% block title %}
<title></title>
{% endblock %}
</head>
<body>
<header>
<div class="container-fluid">
<div class="row">
<div class="col-sm-2">
{% block sidebar %}
<ul class="sidebar-nav list-inline1 p-2">
<li class="list-inline-item1">Home</li>
<li class="list-inline-item1">All books</li>
<li class="list-inline-item1">All authors</li>
</ul>
{% endblock %}
</div>
</div>
</div>
</header>
<div class="container-fluid">
<div class="row">
<div class="col-md-10">
{% block content %}
{% endblock %}
</div>
</div>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"></script>
</body>
</html>
I have just started learning Django and I have hit a little snag and was hoping someone could help.
Problem:
My form is not displaying in my main HTML template (ingredior.html) but the form will display in my test HTML template (test.html) which is just a boiler plate HTML file with the {{form1}} tag in the body. I am changing "return render(request, 'ingredior/ingredior.html', context)" in the views.py file manually to test the two different HTML templates.
ingredior.html
test.html
Question:
Why is the form working in the test.html and not the ingredior.html file when changed?
Please keep in mind that I am swapping this line of code "return render(request, 'ingredior/ingredior.html', context)" with "return render(request, 'ingredior/test.html', context)" to test between the two.
CODE---------
Forms.py
from django import forms
class UserInput(forms.Form):
base_search_ingredient = forms.ChoiceField(choices=[('vegan', 'Vegan'), ('vegatarian', 'Vegatarian')])
views.py
from django.shortcuts import render
import requests
from .local_api_key import Key
from .forms import UserInput
def index (request):
app_id = Key.app_id
app_key = Key.app_key
search_from = 0
search_to = 100
form1 = UserInput()
test = []
if request.POST.get('search'):
test2 = request.POST.get('search')
intolerance = test2
url = requests.get(f"https://api.edamam.com/search?q={intolerance}&excluded=egg&excluded=beef&excluded=dairy&excluded=tomato&excluded=cherry%20tomatoes&excluded=rice&excluded=corn&excluded=soy&excluded=onion&from={search_from}&to={search_to}&health={intolerance}&app_id={app_id}&app_key={app_key}").json()
recipe_length = (len(url['hits']))
else:
intolerance = 'vegan'
url = requests.get(f"https://api.edamam.com/search?q={intolerance}&excluded=egg&excluded=beef&excluded=dairy&excluded=tomato&excluded=cherry%20tomatoes&excluded=rice&excluded=corn&excluded=soy&excluded=onion&from={search_from}&to={search_to}&health={intolerance}&app_id={app_id}&app_key={app_key}").json()
recipe_length = (len(url['hits']))
for urls in range(recipe_length):
recipe_name = (url['hits'][urls]['recipe']['label'])
recipe_url = (url['hits'][urls]['recipe']['url'])
recipe_image = (url['hits'][urls]['recipe']['image'])
recipe_healthLabels = (url['hits'][urls]['recipe']['healthLabels'])
recipe_ingredients = (url['hits'][urls]['recipe']['ingredientLines'])
test.append((recipe_name, recipe_url, recipe_image, recipe_healthLabels, recipe_ingredients))
context = {'test': test, 'form1': form1}
return render(request, 'ingredior/ingredior.html', context)
ingredior.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Nake Recipes</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href=>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
.card {
width: 300px;
height: 700px;
overflow: scroll;
float: left;
margin: 13px;
}
.list {
line-height: 2em;
text-align: left;
}
.card-content ul {
height: 100px
overflow-y: scroll;
}
.container h1 {
text-align: center;
}
</style>
</head>
<body>
<nav>
<div class="container nav-wrapper">
Naked Recipes
<ul id="nav-mobile" class="right">
<li>Home</li>
</ul>
</div>
</nav>
<div class="container">
<h1 style="text-align: c">What intolerance do you have?</h1>
<div class="row">
<div class="col s4">
<!-- Promo Content 1 goes here -->
<div class="center">
<i class="large material-icons" style="color: #EE6E73">flash_on</i>
<p></p>
<p class="light center"></p>
</div>
</div>
<div class="col s4">
<!-- Promo Content 2 goes here -->
<div class="center">
<i class="large material-icons" style="color: orange">camera</i>
<p></p>
<p class="light center"></p>
</div>
</div>
<div class="col s4">
<!-- Promo Content 3 goes here -->
<div class="center">
<i class="large material-icons" style="color: blue">chrome_reader_mode</i>
<p></p>
<p class="light center"></p>
</div>
</div>
</div>
<br>
<form action="" method="post">
{% csrf_token %}
{{ form1 }}
</form>
<br>
<div class="row">
{% for item in test %}
<div class="col_s2">
<div class="card">
<div class="card-image">
<img src= {{ item.2 }} alt="">
</div>
<div class="card-content scroll">
{{ item.0 }}<br><br>
<p>
<b>Ingredients</b><br>
</p>
<ul class="list">
{% for litem in item.4 %}
<li>- {{ litem }}</li>
{% endfor %}
</ul>
<ul class="list">
<p>
<b>Allergies</b>
</p>
{% for litem in item.3 %}
<li>- {{ litem }}</li>
{% endfor %}
</ul>
</div>
<div class="card-action">
<a href={{ item.1 }}>Get Full Recipe </a>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>
test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="" method="post" >
{% csrf_token %}
{{ form1 }}
</form>
</body>
</html>
app/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="index"),
]
Thank you in advance 😅
** UPDATE **
On further investigation :
Inspection Image ingredior.html
Inspection Image test.html
They are the same.
It's giving me an error: NoReverseMatch at / targeting the base.html file (shown in the pic).But the base.html file looks fine to me.
Base.html
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Blog</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Medium Style editor -->
<script src="//cdn.jsdelivr.net/npm/medium-editor#latest/dist/js/medium-editor.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/medium-editor#latest/dist/css/medium-editor.min.css" type="text/css" media="screen" charset="utf-8">
<!-- Custom CSS -->
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Montserrat|Russo+One&display=swap" rel="stylesheet">
</head>
<body class="loader">
<!-- Navbar -->
<nav class="navbar custom-navbar techfont navbar-default">
<div class="container">
<ul class="nav navbar-nav">
<li><a class="navbar-brand bigbrand" href="{% url 'post_list' %}">My Blog</a></li>
<li>About</li>
<li>GitHub</li>
<li>LinkedIn</li>
</ul>
<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li> <a href="{% url 'post_new' %}" >New Post</a></li>
<li> <a href="{% url 'post_draft_list' %}" >Drafts</a></li>
<li> <a href="{% url 'logout' %}" >Logout</a></li>
<li> Welcome: {{user.username}} </li>
{% else %}
<li> <span class="glyphicon glyphicon-user"></span> </li>
{% endif %}
</ul>
</div>
</nav>
<!-- COntent Block -->
<div class="content container">
<div class="row">
<div class="col-md-8">
<div class="blog-posts">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</div>
</body>
</html>
Post_detail.html
{% extends 'blog/base.html' %}
{% block content %}
<h1 class="posttitle loader">{{post.title}}</h1>
{% if post.published_date %}
<div class="date postdate">
{{post.published_date}}
</div>
{% else %}
Publish
{% endif %}
<p class="postcontent">{{post.text|safe|linebreaksbr}}</p>
{% if user.is_authenticated %}
<a href="{% url 'post_edit' pk=post.pk %}" class="btn btn-primary">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<a href="{% url 'post_remove' pk=post.pk %}" class="btn btn-primary">
<span class="glyphicon glyphicon-remove"></span>
</a>
{% endif %}
<hr>
Add Comment
<div class="container">
{% for comment in post.comments.all %}
<br>
{% if user.is_authenticated or comment.approved_comment %}
{{ comment.create_date }}
{% if not comment.approved_comment %}
<a href="{% url 'comment_approve' pk=comment.pk %}" class="btn btn-primary">
<span class="glyphicon glyphicon-ok"></span>
</a>
<a href="{% url 'comment_remove' pk=comment.pk %}" class="btn btn-default">
<span class="glyphicon glyphicon-remove"></span>
</a>
{% endif %}
<p>{{comment.text|safe|linebreaks}}</p>
<p>Posted by: {{comment.author}}</p>
{% endif %}
{% empty %}
<p>No comments!</p>
{% endfor %}
</div>
{% endblock %}
Post_list.html (The very first page that's supposed to be open on running the server)
{% extends 'blog/base.html' %}
{% block content %}
<div class="centerstage">
{% for post in post_list %}
<div class="post">
<h1>{{post.title}}</h1>
<div class="date">
<p>Published on: {{post.published_date|date:'D M Y'}}</p>
</div>
Comments: {{ post.approve_comments.count }}
</div>
{% endfor %}
</div>
{% endblock %}
urls.py
Blog.urls
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$',views.PostListView.as_view(),name='post_list'),
url(r'^about/$',views.AboutView.as_view(),name='about'),
url(r'^post/(?P<pk>\d+)/$',views.PostDetailView.as_view(),name='post_detail'),
url(r'^post/new/$',views.CreatePostView.as_view(),name='post_new'),
url(r'^post/(?P<pk>\d+)/edit/$',views.PostUpdateView.as_view(),name='post_edit'),
url(r'^post/(?P<pk>\d+)/remove/$',views.PostDeleteView.as_view(),name='post_remove'),
url(r'^drafts/$',views.DraftListView.as_view(),name='post_draft_list'),
url(r'^post/(?P<pk>\d+)/comment/$',views.add_comment_to_post,name='add_comment_to_post'),
url(r'^comment/(?P<pk>\d+)/approve/$',views.comment_approve,name='comment_approve'),
url(r'^comment/(?P<pk>\d+)/remove/$',views.comment_remove,name='comment_remove'),
url(r'^post/(?P<pk>\d+)/publish/$',views.post_publish,name='post_publish'),
]
Didn't receive this error before. Came all of a sudden. Clueless as to what went wrong. How to tackle this?
the problem is in post_list.html or post_detail.html .
basically you are having the url that is not matches with any urls in urls.py
ie({% url 'post_detail' pk=post.pk %})
so check your post_list.html and post_detail.html your base.html is well and good
The same error i was facing i looked to my firstly rendered page and the extra url was there.
As it says in the error message, the blog url with arguments {'pk: ''} is not found. This basically means that on the page where you're doing "{% url 'post_detail' pk=post.pk %}", post is probably None or not an object you're expecting. You need to check that your {% for post in post_list %} actually returns posts.
Ok I know this question has been asked before, I looked at the answers and (think) I am doing exactly what is supposed to be done, but the search box is only appearing on the 'search' page and not any other page. I have a base.html that I use to extend to all other pages, can anyone help out on this? (FYI, I did try having the form in base.html instead of search.html but that did not work either)
Base.html
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Search</title>
<link href="{% static 'css/bootstrap3.min.css' %}" rel="stylesheet">
<link href="{% static 'css/main.css' %}" rel="stylesheet">
</head>
<body>
<div class="container">
<header class="clearfix">
{% include 'navbar.html' %}
<h3 class="text-muted">My site</h3>
</header>
<hr>
{% block content %}{% endblock %}
<hr>
<footer>
<p class="text-muted">Copyright © 2015</p>
</footer>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
</body>
</html>
Search.html
{% extends 'base.html' %}
{% load staticfiles %}
{% load widget_tweaks %}
{% block content %}
<h2>Search</h2>
<form method="get" action=".">
<div class="input-group">
{% render_field form.q class+="form-control" type="search" %}
<span class="input-group-btn">
<button type="submit" class="btn btn-default">Search</button>
</span>
</div>
{% if query %}
<h3>Results</h3>
{% for result in page.object_list %}
<div class="media">
<div class="media-left">
<img class="media-object" height="100"
style="border: 1px solid #ccc;"
src="{{ result.object.photo.url }}">
</div>
<div class="media-body">
<h4 class="media-heading">Supplier Part Code: <strong>{{ result.object.supplier_code }}</strong></h4>
<h4>Mfr Code: <strong>{{ result.object.part.code }}</strong></h4>
<p>
<strong>Supplier</strong> {{ result.object.supplier.name }}
<strong>Price</strong> {{ result.object.price }}
<strong>Sale Price</strong> {{ result.object.sale_price }}
<strong>Available</strong> {{ result.object.quantity }}
Buy Now!
</p>
</div>
</div>
{% empty %}
<p>No results found.</p>
{% endfor %}
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}{% endif %}« Previous{% if page.has_previous %}{% endif %}
|
{% if page.has_next %}{% endif %}Next »{% if page.has_next %}{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</form>
{% endblock %}
Manuals.html (No Search bar displays)
{% extends 'base.html' %}
{% load staticfiles %}
{% block content%}
<h1>Hello and welcome to Manuals</h1>
{% endblock %}
URL patterns
url(r'^search/', include('haystack.urls')),
url(r'^manuals/$', 'mysite.views.manuals', name='manuals'),