How to generate a url that redirects to a specific view of another application - django

I'm working on a website, where I want to show all my django project.
So, I have a main app, where i'm generating template for all my projects
my home template when we access to the website:
<!doctype html>
{% load static %}
<html lang="fr">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="{% static 'home/css/style.css' %}">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Nerko+One&family=Roboto&display=swap&family=Open+Sans&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width"/>
</head>
<body>
<header>
<h1></h1>
<span class="separator"></span>
<h2></h2>
<img src="{% static '/home/pictures/logo.png' %}" alt="logo" title="Ceci est mon logo" id="logo">
</header>
<nav>
<ul>
<li>Accueil</li>
<li>Projets</li>
<li>Contact</li>
</ul>
</nav>
<div class="contener">
<section>
<h3>Projets</h3>
<!-- conteneur -->
<div id="projects">
{% for projet in projets %}
<div class="project">
<a href="{% url 'projet-detail' projet.nom_lien %}">
<div class="picture">
<img src="{% static '' %}{{ projet.lien_image_presentation }}" alt="Présentation {{ projet.nom }}">
</div>
<span>{{ projet.nom }}</span>
<span class="date-project">{{ projet.date }}</span>
</a>
</div>
{% endfor %}
</div>
</section>
<section>
<h3>Contact</h3>
<div id="contact">
<p>Si vous désirez me contacter, n'hésitez pas à m'écrire à l'adresse <b>aymerick.cotche#hotmail.fr</b></p>
</div>
</section>
</div>
<footer>
<span>2020 © - Aymerick Cotche</span>
</footer>
</body>
</html>
template to see my project description :
{% load static %}
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>{{ projet.nom }} | {{ projet.auteur }}</title>
<link rel="stylesheet" type="text/css" href="{% static 'home/css/style.css' %}">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Nerko+One&family=Roboto&display=swap&family=Open+Sans&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width"/>
</head>
<body>
<header>
<h1></h1>
<span class="separator"></span>
<h2>{{ projet.nom }}</h2>
</header>
<nav>
<ul>
<li>Accueil</li>
<li>Projets</li>
<li>Contact</li>
</ul>
</nav>
<div class="contener">
<section>
<h3>Introduction</h3>
<p> {{ projet.description }} </p>
</section>
<section id="production_project">
<h3>Production</h3>
<img src="{% static '' %}{{ projet.lien_image_production }}" alt="mon premier projet">
voir le projet
</section>
</div>
</body>
</html>
my urls file for this app:
from django.urls import path
from home import views
urlpatterns = [
path('', views.home),
path('<str:nom_lien>/', views.projet_detail, name='projet-detail'),
]
My views file for this app :
from django.shortcuts import render, redirect
from home.models import Projet
def home(request):
projets = Projet.objects.all().order_by('numero')
return render(request, 'home/index.html', {'projets': projets})
def projet_detail(request, nom_lien):
projet = Projet.objects.get(nom_lien=nom_lien)
context = {
'projet': projet
}
return render(request, 'home/projets_base.html', context)
That I want to do it's to have a link in my project description template, to go to the project, and use the project. The project it's another django app in the same project. and this link should be like "/nom-lien/voirprojet/"
For example in my app "pizza mama" I have this url and views file:
from django.urls import path
from . import views
app_name = "main"
urlpatterns = [
path('pizzamama/voirprojet/', views.index, name="index"),
]
The link have to use the Projet.nom_lien field in my database and redirect to the the project page.
Could someone help me please, I'm stuck and can't make it works.

you want to store the link in the database
define in models.py a class Project
class Project(models.Model):
link_to_app = models.CharField(max_length=50)
register it in the admin.py
in the admin panel enter the what you want Links
then you can access it like this in urls.py
from .models import Link
link = Projects.objects.get(pk=1)
my_link = link.link_to_app
then pass my_link to the url path
urlpatterns += [
path(my_link, views.index, name='index')),
]

Related

Django NoReverseMatch - Amadeus API

I'm attempting to use an API as part of a project I'm working on and am having some difficulty currently:
API
https://developers.amadeus.com/self-service/category/air/api-doc/airport-and-city-search
API - Python SDK
https://github.com/amadeus4dev/amadeus-python
Django API Guide
https://developers.amadeus.com/blog/django-jquery-ajax-airport-search-autocomplete
I have followed the instructions from the above guide; however, I am receiving the following error when trying to render the index page which contains the code:
Reverse for 'origin_airport_search' not found. 'origin_airport_search' is not a valid view function or pattern name.
Index Template:
{% extends "flightfinder/layout.html" %}
{% block body %}
<div id="mainhomepagediv">
<div class="container-fluid px-0" id="mainhomepagediv">
<div class="row mx-0">
<div class="col-12 px-0">
<img src="https://i.ibb.co/rHYzcyc/Landscape2.jpg" class="img-fluid w-100">
</div>
</div>
</div>
<div>
<h1 id="homepageh1">Where are you flying to?</h1>
<div id="homepagebox">
<div>
<form id="homepageform" method="POST">
<div class="row">
<div class="col">
<label id="homepageformlabel">From</label>
<input type="text" class="form-control" placeholder="Origin city" id="inputOrigin">
</div>
<div class="col pb-3">
<label id="homepageformlabel">To</label>
<input type="text" class="form-control" placeholder="Destination city">
</div>
</div>
<div class="row">
<div class="col">
<label id="homepageformlabel">Depart</label>
<input type="date" class="form-control" placeholder="Origin city">
</div>
<div class="col">
<label id="homepageformlabel">Return</label>
<input type="date" class="form-control" placeholder="Destination city">
</div>
<div class="col-6">
<label id="homepageformlabel">Class</label>
<select id="inputState" class="form-control">
<option selected>Economy</option>
<option>Business</option>
<option>First</option>
</select>
</div>
</div>
<div class="row">
<div class="col">
</div>
<div class="col-3 pt-3">
<button class="btn float-right" id="homepageformbutton" type="submit">Search flights</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
// Amadeus origin airport search
$(document).ready(function () {
$("#inputOrigin").autocomplete({
source: "{% url 'origin_airport_search' %}",
minLength: 1,
delay: 200,
});
});
</script>
{% endblock %}
Layout Template:
{% load static %}
<!doctype html>
<html lang="en">
<head>
<!-- jQuery & jQuery UI -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<!-- Bootstrap (includes Popper) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Main CSS-->
<link rel="stylesheet" type="text/css" href="{% static 'flightfinder/styles.css' %}">
<!-- Main JS -->
<script src="{% static 'flightfinder/main.js' %}"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<title>{% block title %}Flight Finder{% endblock %}</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light">
<a class="navbar-brand" href="{% url 'flightfinder:index' %}">
<img src="https://i.ibb.co/TRBkPBZ/Flight-Finder-removebg-preview.png" width="166" height="42" class="d-inline-block align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="{% url 'flightfinder:index' %}">Flights <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">Hotels</a>
<a class="nav-item nav-link" href="#">Car Hire</a>
</div>
</div>
</nav>
{% block body %}
{% endblock %}
</body>
</html>
Main - urls.py:
"""finalproject URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('flightfinder.urls', namespace='Flightfinder')),
path('admin/', admin.site.urls),
]
App - urls.py:
from django.urls import path
from . import views
app_name = 'flightfinder'
urlpatterns = [
path('', views.index, name='index'),
path('origin_airport_search/', views.origin_airport_search, name='origin_airport_search')
]
views.py:
import json
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib import messages
from amadeus import Client, ResponseError, Location
from .models import Airport, Flight, Passenger
amadeus = Client(client_id='removed',
client_secret='removed',
log_level='debug')
# Create your views here.
def index(request):
return render(request, 'flightfinder/index.html')
def origin_airport_search(request):
if request.is_ajax():
try:
data = amadeus.reference_data.locations.get(keyword=request.GET.get('term', None), subType=Location.ANY).data
except ResponseError as error:
messages.add_message(request, messages.ERROR, error)
return HttpResponse(get_city_airport_list(data), 'application/json')
def get_city_airport_list(data):
result = []
for i, val in enumerate(data):
result.append(data[i]['iataCode']+', '+data[i]['name'])
result = list(dict.fromkeys(result))
return json.dumps(result)
I have had a look through some similar stack queries, but none of them have helped thus far. Would be grateful if somebody had any ideas to try here?
Thank you!
You have set a namespace "Flightfinders" in your include. This means you have to use this namespace to call your URL:
source: "{% url 'Flightfinder:origin_airport_search' %}",

I am trying to use static files like css and images in my django project but statics files are not displayed in my template page

I want a image to be displayed in my navbar at the top left corner but its not visible and my css styling is also not styling my pages....in short my static files are not displayed in my project.
i think i have mentioned all the neccesary things if anything is missing please mention.
my settings.py----
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
STATIC_FILES = os.path.join(BASE_DIR,'static','static_files')
STATIC_ROOT = os.path.join(BASE_DIR,'static','static_root')
urls.py---
from Devishi import settings
from django.conf.urls.static import static
urlpatterns = [
path('',views.home,name='home'),
path('product/',views.products,name ='product'),
path('customer/',views.customer,name ='customer'),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
main.html---
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>{% block title %}DASHBORD||{% endblock %}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="{% static '/css/my.css' %}">
</head>
<body>
{% include 'app/navbar.html' %}
{% block content %}
{% endblock %}
<hr/>
<p>Our Footer</p>
</body>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" 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.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</html>
navbar.html---
{% load static %}
<style media="screen">
.hello-msg{
font-size:18px;
color:#fff;
margin-right:20px;
}
</style>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<img src="{% static "img/logo.png" %}" alt="image">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'product' %}">Products</a>
</li>
</ul>
</div>
</nav>

Model in header doesn't appear in views that use the header

Model defined in the header of my pages appears on page load and refresh on the main page, but when I navigate to another view the model doesn't appear there. The rest of the header is there, just the dynamic data that isn't.
Where am I going wrong? New to both Python and Django, so if anyone can help, please don't be afraid to patronize and Eli5 :)
Model defined in models.py:
from django.db import models
from django.utils import timezone
# Create your models here.
class Propaganda(models.Model):
slogan = models.CharField(max_length=140, blank=True, null=True)
def __str__(self):
return self.slogan
header.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Christopher's weblog</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Blog site.">
<!-- Let's get the static files where we use them, but this could be before the html tag -->
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'blog/css/bulma.css' %}" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- <link rel="stylesheet" href="{% static 'blog/css/cupar.css' %}" type="text/css" /> -->
</head>
<body>
<section class="hero is-success is-bold">
<div class="hero-body">
<div class="container">
{% block slogan %}
{% for propaganda in propagandas %}
<h6>{{ propaganda.slogan }} it's</h6>
{% endfor %}
{% endblock %}
<h1 class="title" style="display: inline-block;">
<span class="icon">
<i class="fa fa-home"></i>
</span>
The Guide
</h1>
{% if user.is_authenticated %}
<div class="field">
<div class="control">
<a href="{% url 'post_new' %}" class="button is-warning is-pulled-right">
<span class="icon">
<i class="fa fa-plus-square"></i>
</span>
<span>New post</span>
</a>
</div>
</div>
{% endif %}
</div><!-- #container -->
</div>
</section>
<!-- content under header in here-> -->
{% block content %}
{% endblock %}
</body>
</html>
views.py
from django.template import RequestContext
from django.shortcuts import render, get_object_or_404, redirect
from .models import Post, Propaganda
from .forms import PostForm
from django.utils import timezone
# Create your views here.
def post_list(request):
posts = Post.objects.all()
propagandas = Propaganda.objects.all().order_by('?')[:1]
return render(request, 'blog/post_list.html', {'posts': posts, 'propagandas': propagandas})
post_detail.html (where the model does not appear):
{% extends 'blog/header.html' %}
{% block content %}
some html / form that has nothing to do with the header.
{% endblock %}
post_list.html (the 'index' page where the model works fine)
{% extends "blog/header.html" %}
{% block content %}
{% for post in posts %}
<section class="section">
more html
{% endblock %}
need to pass the data from each view function that is required in the header you are extending (re-using) in each template.
def post_detil(request, id):
posts = Post.objects.all()
propagandas = Propaganda.objects.all().order_by('?')[:1]
# ... add in other stuff relevant to post details ...
post = Post.objects.get(pk=id)
return render(request, 'blog/post_detail.html', {'posts': posts, 'propagandas': propagandas, 'post': post})
Stick with it #Rin and Len, you'll get there :)
First: Why are you not showing the view of post_detail. Isn't that the one that does not work?
Second: Even though you are extending a base template you still have to pass the appropriate context in order to generate the desired dynamic data.
I hope it helps.

how to fix NoReverseMatch at? work if you not authorized

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

Django 1.9: NoReverseMatch

I have a class based view which shows the data in template having {% extends 'base.html' %}.
My base file folder is in seperate folder called products
My App url
urlpatterns = [
url(r'^contact/', views.contact, name='contact'),
url(r'^product_list/', views.ProductViewList.as_view(), name='ProductViewList'),
]
Template of class based view (product_list.html)
{% extends 'base.html' %}
{% block content %}
{{ object_list }}
{% endblock %}
My 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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="{% static 'img/favicon.ico' %}">
<title>Starter Template for Bootstrap</title>
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'css/starter-template.css' %}" rel="stylesheet">
</head>
<body>
{% include 'navbar.html' %}
<div class="container">
{% block content %}
{% endblock %}
</div><!-- /.container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="{% static 'js/jquery.min.js' %}"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="{% static 'js/ie10-viewport-bug-workaround.js' %}></script>
</body>
</html>
When i visit "http://127.0.0.1:8000/product/product_list/" following error pops up
My directory structure, My base.html is in root directory(templates) and product_list.html is in products folder
I think there could be problem with {% extends 'base.html' %}, But not sure how to sole the problem.......Any help is much appreciated
Here's my first urls...which further redirects to my app url.py
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^product/', include('products.urls')),
url(r'^accounts/', include('registration.backends.default.urls')),
]
You need to specify a name to the view url that identify when you want to used in the template
from django.conf.urls import url
import myapplication.views
app_urlpatterns = [
url(r'^article/(\d+)/$',views.article_detail,name='article-view-url'),
]
And this is how I use the url name in my html template
{% for article in articles.object_list %}
<article>
<h3>
{{ article.name }}
</h3>
<p>
{{ article.desc }}
</p>
</article>
{% endfor %}