Django NoReverseMatch - Amadeus API - django

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' %}",

Related

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/accounts/register.html

Working on *django * on a test app, while creating a subpage as register in index/homepage, facing an error as follows:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
[name='index']
admin/
accounts
^media/(?P.*)$
The current path, accounts/register.html, didn’t match any of these.
views.py:
from django.shortcuts import render
def register(request):
return render(request,'register.html')
urls.py:
from django.urls import path
from . import views
urlpatterns = [
path("register",views.register, name="register")
]
mysite url.py:
from django.contrib import admin
from django.urls import include , path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('',include('Sell.urls')),
path('admin/', admin.site.urls),
path('accounts', include('accounts.urls'))
]
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
index.html:
<div class="container">
<div class="header_section_top">
<div class="row">
<div class="col-sm-12">
<div class="custom_menu">
<ul>
<li>Best Sellers</li>
<li>Gift Ideas</li>
<li>New Releases</li>
<li>Register</li>
<li>Customer Service</li>
</ul>
</div>
</div>
</div>
</div>
</div>
#Although the register.html is in a templates folder but i tried it too but still not working.
Register.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv='X-UA-Compatible' content="IE=edge">
<title>Register</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="main.css">
<script src="main.js"></script>
</head>
<body>
<form action='register' method='post'>
{% csrf_token %}
<input type="text" name="first_name" placeholder="First Name"><br/>
<input type="text" name="last_name" placeholder="Last Name"><br/>
<input type="text" name="username" placeholder="username"><br/>
<input type="Email" name="Email" placeholder="Email"><br/>
<input type="Password" name="Pasword1" placeholder="Pasword"><br/>
<input type="Password" name="Password2" placeholder="Confirm Pasword"><br/>
</form>
</body>
</html>
you should use the django template tag:
<li>Register</li>
which refers to the "name" in the path definition in urls.py

Getting NoReverse match error upon passing context variable in {% url contextVariable %} in Django

In my Django project, I am experiencing an where the revers url cannot be found. Basically I passed a context variable in the template's {% url navLogoLinkName %}, I checked from the source html code generated by the page that the navLogoLinkName generates the right link. When clicking on the link however, I get a NoReverseMatch error.
In my urls.py, you can see that I have a path with name = 'hiddendimsum_nytorv'
"""website 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 path
from django.urls.conf import re_path
from index.views import indexPage, hdnytorv, hd2900, hdbynight
from takeawayWebshop.views import TakeawayWebshopMain
from webshopCart.views import AddRemoveCartItems
from django.conf import settings
from django.conf.urls.static import static
from django.views.static import serve
admin.autodiscover()
urlpatterns = [
path('admin/', admin.site.urls),
path('', indexPage.as_view()),
path('hdnytorv', hdnytorv.as_view(), name='hiddendimsum_nytorv'),
path('hd2900', hd2900.as_view(), name='hiddendimsum_2900'),
path('hd2900_takeaway_webshop', TakeawayWebshopMain.as_view(), name="hiddendimsum_takeaway_webshop"),
path('changeItemQuantityInBasket', AddRemoveCartItems.as_view()),
#path('check-address-for-deliverable', AddressCheckForDeliverability.as_view()),
#path('changeItemQuantityInBasket', ChangeItemQuantity.as_view()),
#path('getTakeawayClosingOrderTime', lastPickupDeliveryOrderTime.as_view()),
#path('isPriceAboveDeliveryLimit', totalPriceDeliveryPossible.as_view()),
path('hdbynight', hdbynight.as_view(), name='hiddendimsum_bynight'),
#path('takeawayCheckout', TakeawayCheckout.as_view()),
#path('deliveryFormCheckout', DeliveryForm.as_view()),
#path('pickupFormCheckout', PickUpForm.as_view()),
#path('local_delivery_checkout_is_address_deliverable', localDeliveryCheckoutAddressCheck.as_view()),
#path('process_pickup_or_delivery_form', deliveryPickupFormProcess.as_view()),
#path('localDeliveryPayment', Payment.as_view(), name = 'localDeliveryPayment'),
#path('getPaymentId', getPaymentId.as_view()),
#path('paymentComplete', PaymentComplete.as_view(), name = 'paymentComplete'),
#path('paymentNotification', paymentNotificationWebhook),
#path('verifyPayment', paymentVerificationStaticPage.as_view(), name = 'verifyPayment'),
#path('backendPaymentVerification', backendPaymentVerification.as_view()),
re_path(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
]
#When in production medida url must always be added to urlpatterns
#if settings.DEBUG:
#urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
In my template I have href="{% url navLogoLinkName %}" where navLogoLinkName is the context variable passed from the view.
{% load static %}
<nav class="navbar navbar-expand-lg navbar-light bg-secondary" id ="navbar">
<button class="navbar-toggler m-auto" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="#navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand navbar-left" href="{% url navLogoLinkName %}" id="navbarLogoLink">
<img src="{{ navbarLogoPath }}" alt="{{ navbarLogoAlt }}" id="navbarLogo">
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
{% for link in links %}
{% if link.0 == 'BOOK TABLE' %}
<li class="nav-item active" id="navbarListItem">
<a class="nav-link px-6" id ="mainNavlink" href="{{ link.1 }}" target="_blank"><h3 id="linkText">{{ link.0 }}</h3></a>
</li>
{% else %}
<li class="nav-item active" id="navbarListItem">
<a class="nav-link px-6" id ="mainNavlink" href="{{ link.1 }}"><h3 id="linkText">{{ link.0 }}</h3></a>
</li>
{% endif %}
{% endfor %}
</ul>
{% if controlReport %}
{% autoescape off %}
<a class="pull-right" href={{controlReport}} target="_blank">
<img src={% static 'media/kontrolRapport.gif' %} width="15%" height = auto>
</a>
{% endautoescape %}
{% endif %}
</div>
</nav>
In views.py I have context['navLogoLinkName'] = 'hiddendimsum_nytorv'. From urls.py, you can see that hiddendimsum_nytorv should point to hdnytorv in path.
from webshopCart.models import CartItem
from .models import TakeawayWebshop
from restaurant.models import Restaurant
# Create your views here.
from django.shortcuts import render
from django.views import View
from django.conf import settings
from website.Modules.webshopUtils import Session, getTotalItemsInCart
webshopName = 'Hidden Dimsum 2900'
class TakeawayWebshopMain(View):
def get(self, request, *args, **kwargs):
context = dict()
context['navbarLogoPath'] = 'static/media/hd2900coverLogo.png'
context['navLogoLinkName'] = 'hiddendimsum_nytorv'
context['links'] = list()
context['aboutUsRestaurant'] = Restaurant.objects.filter(name = webshopName)[0]
#Import the webshop object followed by the products
webshop = TakeawayWebshop.objects.filter(name = webshopName)
webshop = webshop[0]
products = webshop.getProducts()
#Check if session exists
session = Session(request = request)
isSessionValid = session.isSessionValid(webshopModelObject = webshop)
context['sessionValidity'] = isSessionValid
#Get product quantity if session exists
productToDisplay = list()
for product in products:
productDict = dict()
productDict['product'] = product
if isSessionValid:
cartItem = CartItem.objects.filter(session_id = request.session[settings.WEBSHOP_SESSION_KEY],
product = product)
if cartItem:
productDict['quantity'] = cartItem[0].quantity
else:
productDict['quantity'] = 0
else:
productDict['quantity'] = 0
productToDisplay.append(productDict)
context['products'] = productToDisplay
if isSessionValid:
context['totalCartItems'] = getTotalItemsInCart(request = request)
else:
context['totalCartitems'] = 0
print('from webshop main')
print(context)
return render(request, template_name="takeawayWebshopMain.html", context = context)
Below are the source html generated from the rendered page. You can see this snippet
<a class="navbar-brand navbar-left" href="/hdnytorv" id="navbarLogoLink">
<img src="static/media/hd2900coverLogo.png" alt="" id="navbarLogo">
</a>
which demonstrates that it is pointing to the correct link as in my urls.py.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap css-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!--social media icons-->
<link rel="stylesheet" type="text/css" href=/static/landingPage.css>
<link rel="stylesheet" type="text/css" href=/static/takeawayWebshop.css>
<title></title>
<!--SEO-->
<meta name="description" content="Hidden Dimsum 2900, Strandvejen 163, Hellerup online dimsum takeaway and local delivery webshop">
<meta name="keywords" content="Hidden Dimsum 2900, dimsum takeaway webshop, dimsum local delivery, dumplings takeaway, online ordering">
<meta name="author" content="Hidden Dimsum 2900">
<link rel="shortcut icon" type="image/png" href="/static/media/favicon_hd32x32.png"/>
<!--Font awesome-->
<script src="https://kit.fontawesome.com/efc09bd617.js" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<!--Google Analytics-->
<!-- Global site tag (gtag.js) - Google Analytics -->
<!--Easy table booking-->
<!--Easy table booking embedded-->
<script type="text/javascript">
(function() { var st=document.createElement('script'); st.type='text/javascript'; st.async=true; st.src='//book.easytablebooking.com/javascripts/widget/v2/book.js'; var sc=document.getElementsByTagName('script')[0]; sc.parentNode.insertBefore(st, sc); })();
</script>
<noscript>Your browser does not support JavaScript!</noscript>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-secondary" id ="navbar">
<button class="navbar-toggler m-auto" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="#navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand navbar-left" href="/hdnytorv" id="navbarLogoLink">
<img src="static/media/hd2900coverLogo.png" alt="" id="navbarLogo">
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
</ul>
</div>
</nav>
<div class="container-fluid sticky-top" id="takeawayHeaderCartContainer">
<div class="row">
<div class="col-11" id="cartIconContent">
<a href="/takeawayCheckout">
<i class="fa" id="shoppingCartIcon"></i> <!--this code codes for the shopping cart icon-->
<span class='badge badge-warning' id='lblCartCount'>
0
</span>
</a>
</div>
</div>
</div>
<div class="container-fluid h-100">
<h1 class="contentHeader">Menu</h1>
<hr class = "titleHorisontalLine">
<div class="row row-cols-1 row-cols-md-4">
<div class="col-auto mt-5">
<div class="card h-100 text-center">
<div class="card-body">
<!--Title -->
<h5 class="card-title">Charr Siu Bao</h5>
<!--Product image with link -->
<img class="card-img embed-responsive-item" src="/media/productImages/DimsumBox.jpg" alt="">
<!--Product description-->
<p class="card-text">some descriptions here</p>
<!--Allergic note -->
<p class="card-text">allergy notes</p>
<!--Price-->
<h5 class="mt-4">100,- </h5>
<div class="input-group">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary subtractItem" type="button" id="btn_subtract_charr-siu-bao" onclick="itemQuantityChangeButton(this)">
-
</button>
</div>
<input type="text" class="form-control" id="text_charr-siu-bao" placeholder="0" aria-label="ordered amount" aria-describedby="basic-addon1" readonly>
<div class="input-group-append">
<button class="btn btn-outline-secondary addOneItem" type="button" id="btn_add_charr-siu-bao" onclick="itemQuantityChangeButton(this)">
+
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col-auto mt-5">
<div class="card h-100 text-center">
<div class="card-body">
<!--Title -->
<h5 class="card-title">Product A</h5>
<!--Product image with link -->
<img class="card-img embed-responsive-item" src="/media/productImages/duckGaozi_TAI2jqx.jpg" alt="">
<!--Product description-->
<p class="card-text">product A description</p>
<!--Allergic note -->
<!--Price-->
<h5 class="mt-4">100,- </h5>
<div class="input-group">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary subtractItem" type="button" id="btn_subtract_product-a" onclick="itemQuantityChangeButton(this)">
-
</button>
</div>
<input type="text" class="form-control" id="text_product-a" placeholder="0" aria-label="ordered amount" aria-describedby="basic-addon1" readonly>
<div class="input-group-append">
<button class="btn btn-outline-secondary addOneItem" type="button" id="btn_add_product-a" onclick="itemQuantityChangeButton(this)">
+
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col-auto mt-5">
<div class="card h-100 text-center">
<div class="card-body">
<!--Title -->
<h5 class="card-title">Product B</h5>
<!--Product image with link -->
<img class="card-img embed-responsive-item" src="/media/productImages/duckGaozi_BcevHBI.jpg" alt="">
<!--Product description-->
<p class="card-text">product B description</p>
<!--Allergic note -->
<!--Price-->
<h5 class="mt-4">200,- </h5>
<div class="input-group">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary subtractItem" type="button" id="btn_subtract_product-b" onclick="itemQuantityChangeButton(this)">
-
</button>
</div>
<input type="text" class="form-control" id="text_product-b" placeholder="0" aria-label="ordered amount" aria-describedby="basic-addon1" readonly>
<div class="input-group-append">
<button class="btn btn-outline-secondary addOneItem" type="button" id="btn_add_product-b" onclick="itemQuantityChangeButton(this)">
+
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col-auto mt-5">
<div class="card h-100 text-center">
<div class="card-body">
<!--Title -->
<h5 class="card-title">Product C</h5>
<!--Product image with link -->
<img class="card-img embed-responsive-item" src="/media/productImages/porkGaozi_min_xa7mpZQ.jpg" alt="">
<!--Product description-->
<p class="card-text">Product C description</p>
<!--Allergic note -->
<!--Price-->
<h5 class="mt-4">300,- </h5>
<div class="input-group">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary subtractItem" type="button" id="btn_subtract_product-c" onclick="itemQuantityChangeButton(this)">
-
</button>
</div>
<input type="text" class="form-control" id="text_product-c" placeholder="0" aria-label="ordered amount" aria-describedby="basic-addon1" readonly>
<div class="input-group-append">
<button class="btn btn-outline-secondary addOneItem" type="button" id="btn_add_product-c" onclick="itemQuantityChangeButton(this)">
+
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col-auto mt-5">
<div class="card h-100 text-center">
<div class="card-body">
<!--Title -->
<h5 class="card-title">pork gaozi</h5>
<!--Product image with link -->
<img class="card-img embed-responsive-item" src="/media/productImages/porkGaozi.jpg" alt="">
<!--Product description-->
<p class="card-text">here is description for pork gaozi</p>
<!--Allergic note -->
<!--Price-->
<h5 class="mt-4">50,- </h5>
<div class="input-group">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary subtractItem" type="button" id="btn_subtract_pork-gaozi" onclick="itemQuantityChangeButton(this)">
-
</button>
</div>
<input type="text" class="form-control" id="text_pork-gaozi" placeholder="0" aria-label="ordered amount" aria-describedby="basic-addon1" readonly>
<div class="input-group-append">
<button class="btn btn-outline-secondary addOneItem" type="button" id="btn_add_pork-gaozi" onclick="itemQuantityChangeButton(this)">
+
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid d-flex justify-content-end">
<div class="row">
<a href="/takeawayCheckout" role="button" id="checkoutLink">
<button type="button" class="btn btn-success btn-lg">Checkout</button>
</a>
</div>
</div>
<footer class="bg-dark text-center text-white">
<div class="container p-4 mx-auto">
<a href="https://www.facebook.com/Hiddendimsum2900" target="_blank" class="footerIcon">
<i class="fa-brands fa-facebook fa-3x"></i>
</a>
<a href="https://www.instagram.com/hiddendimsum2900" target="_blank" class="footerIcon">
<i class="fa-brands fa-instagram fa-3x"></i>
</a>
</div>
<div class="container p-2 mx-auto">
<form method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="nVitBexkVreopuERtPpFqceQ7iImmDAyg6WLG8rqNj7dyZCuaZwwKsOfCf3EJSjo">
<p><label for="newLetterEmailLabel" class="bodyText" id="newLetterEmailLabel">Newsletter Subscription</label></p>
<input type="email" name="subscriptionEmail" placeholder="email#example.com">
<button type="submit" name="action" class="btn btn-primary" value="emailSubscription" id="newsLetterSubmitButton">Subscribe</button>
</form>
</div>
<div class="text-center footerText p-3" id="footerAddress">
©Hidden Dimsum 2900
<br>
Strandvejen, 163, 2900, Hellerup
<br>
CVR: 38908901
<br>
Phone : +45-40388884
</div>
</footer>
<script src="/static/scripts/product_add_subtract_btn_clicked.js"></script>
<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/#popperjs/core#2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
</body>
</html>
Still when clicking on the navbar logo image, I get the below error
Internal Server Error: /hdnytorv
...
django.urls.exceptions.NoReverseMatch: Reverse for '/' not found. '/' is not a valid view function or pattern name.
[02/Apr/2022 23:46:16] "GET /hdnytorv HTTP/1.1" 500 209584
You can use "URL Namespaces". Add an "app-name" in your urls.py:
app_name = 'myAppName'
...
path('hd2900', hd2900.as_view(), name='hd2900')
...
And in your template, use {% url 'myAppName:hd2900' %}:
<a class="navbar-brand navbar-left" href="{% url 'myAppName:hd2900' %}" id="navbarLogoLink">
<img src="{{ navbarLogoPath }}" alt="{{ navbarLogoAlt }}" id="navbarLogo">
</a>

Python django, when creating an registering form how to get this .get method working?

I started to watch Corey Schafer's django website tutorial and everything was going great until now. unlike in the video after registering site doesn't sends me to home page. It does nothing. All I suspect is the get method because it is not the color it supposed to be in VSC. Any ideas why :(
and also .method functions seems to be not working it is white in VSC
user_views.py:
from django.contrib import messages
from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import redirect, render
def register(request):
if request.method =='POST':
form = UserCreationForm(request.POST)
if form.is_valid():
username=form.cleaned_data.get('username')
messages.success(request,f'Account Created for {username}')
return redirect("blog-home")
else:
form=UserCreationForm()
return render(request,'users/register.html',{'form':form})
here is the urls:
from django.contrib import admin
from django.urls import path, include
from users import views as user_views
urlpatterns = [
path('admin/', admin.site.urls),
path("", include('Blog.urls')),
path("register/",user_views.register,name="register")
]
Blog.urls:
from django.urls import path
from . import views
urlpatterns= [
path("",views.Home,name="blog-home"),
path("about/",views.About, name="blog-about"),
]
templates:
{% extends "Blog/base.html" %}
{% block content %}
<div class='content-section'>
<form method='POST'>
{% csrf_token %}
<fieldset class="form_group">
<legend class="border-bottom mb-4">Join Today</legend>
{{ form.as_p }}
</fieldset>
<div class="form-group">
<button class="btn btn-outlline-info" type="submit">
Sign Up
</button>
</div>
</form>
<div class="boder-top pt-3">
<small class="text-muted">
Already Have An Account? <a class="ml-2" href="#"> Sign In </a>
</small>
</div>
</div>
{% endblock content %
base template:
{% load static %}
<!DOCTYPE html >
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{% static 'Blog/main.css' %}">
{% if title %}
<title> {{title}} </title>
{% else %}
<title> Django Project </title>
{% endif %}
</head>
<body>
<header class="site-header">
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
<div class="container">
<a class="navbar-brand mr-4" href="{%url 'blog-home'%}">Django Blog</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarToggle">
<div class="navbar-nav mr-auto">
<a class="nav-item nav-link" href="{%url 'blog-home'%}">Home</a>
<a class="nav-item nav-link" href="{% url 'blog-about' %}">About</a>
</div>
<!-- Navbar Right Side -->
<div class="navbar-nav">
<a class="nav-item nav-link" href="#">Login</a>
<a class="nav-item nav-link" href="{%url 'register' %}">Register</a>
</div>
</div>
</div>
</nav>
</header>
<main role="main" class="container">
<div class="row">
<div class="col-md-8">
{% if messages %}
{% for message in messages %}
<div class="Alert alert-{{ message.tags}}">
{{message}} </div>
{% endfor %}
{% endif %}
{% block content %}{% endblock %}
</div>
<div class="col-md-4">
<div class="content-section">
<h3>Our Sidebar</h3>
<p class='text-muted'>You can put any information here you'd like.
<ul class="list-group">
<li class="list-group-item list-group-item-light">Latest Posts</li>
<li class="list-group-item list-group-item-light">Announcements</li>
<li class="list-group-item list-group-item-light">Calendars</li>
<li class="list-group-item list-group-item-light">etc</li>
</ul>
</p>
</div>
</div>
</div>
</main>
People who had a problem with PATH variables before listen me carefully this might save you a lot of time, Although I still don't know why and how. There is a django_settings module which is not present anywhere or maybe I couldn't find the exact folder but however this module can be set to your projects setting module that fixes the problem:
set DJANGO_SETTINGS_MODULE=mysite.settings
django-admin runserver
from the terminal, this sets your path of settings I guess

I want to get the vote button with proper functionality but I'm unable to do that

I want vote button that works properly, when user clicks that button it should increase the number of votes there itself.
views.py
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from . models import Question, Choice
from django.urls import reverse
# Create your views here.
def base(request):
return render(request, 'base.html')
def home(request):
return render(request, 'home.html')
def quest(request):
question_list=Question.objects.all()
context={'question_list': question_list}
return render(request, 'quest.html', context)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.base, name='base'),
path('home', views.home, name='home'),
path('quest', views.quest, name='quest'),
]
base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<title>Voting World</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="{% url 'home' %}">Home</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 ml-auto">
<a class="nav-item nav-link active" href="#">About us</a>
<a class="nav-item nav-link active" href="#"><i class="fas fa-user"></i> Login</a>
<a class="nav-item nav-link active" href="#"><i class="fas fa-sign-in-alt"></i> Signup</a>
</div>
</div>
</nav>
<div class="container">
{% block body %}
{% endblock %}
</div>
</body>
</html>
quest.html
{% extends 'base.html' %}
{% block body %}
{% if question_list %}
<ul style="list-style: none;">
{% for question in question_list %}
<div class="row mt-3 text-danger">
<li><h3>{{ question.title }}</h3><p style="color: #072e6e">{{ question.pub_date }}</p></li>
</div>
<div class="row mt-3">
<div class="col-md-5">
<li><img src="{{ question.image1.url }}"></li>
</div>
<div class="col-md-2">
<h1 style="font-size: 180px; margin-left: -95px;">v/s</h1>
</div>
<div class="col-md-5">
<li><img src="{{ question.image2.url }}"></li>
</div>
</div>
<div class="row">
<div class="col-md-5">
<button class="btn btn-success">Vote</button>
</div>
<div class="col-md-5">
<button class="btn btn-success">Vote</button>
</div>
</div>
{% endfor %}
</ul>
{% else %}
<p>No Polls Available!!..</p>
{% endif %}
{% endblock %}
models.py
from django.db import models
# Create your models here.
class Question(models.Model):
title = models.CharField(max_length=100)
image1 = models.ImageField(upload_to='pics')
image2 = models.ImageField(upload_to='pics')
pub_date = models.DateTimeField()
def __str__(self):
return self.title
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
vote1 = models.IntegerField(default=0)
vote2 = models.IntegerField(default=0)
i expected the output when user click the vote, it should increase the value of vote by 1, i.e. vote+1....but I'm not getting how to do that.

'set' object is not reversible [duplicate]

I'm just trying to make a simple connection to another page using the url tag in Django. I'm getting a error of "'set' object is not reversible". After searching for a bit I've been unsuccessful in finding anything.
urls.py
from django.conf.urls import url
from . import views
APP_NAME = 'website'
urlpatterns = {
url(r'^$', views.admin_view, name='adminview'),
url(r'^eventview/$', views.event_view, name='eventview'),
}
admin_view.html
<!DOCTYPE html>
<html lang="en" >
<head>
{% load static %}
{% block header%}
{% include 'website/header.html' %}
{% endblock %}
<!-- Insert custom css here -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<!-- top navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Vivid Fireworks</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>Dashboard</li>
<li>Add Show</li>
<li>Settings</li>
<li>Profile</li>
<li>Help</li>
</ul>
</div>
</div>
</nav>
I haven't ran into this problem before and it seems like it'll be a simple fix just something I'm over looking. Any help is appreciated.
urlpatterns should be a list [...]. You currently have a set {...}. It should be:
urlpatterns = [
url(r'^$', views.admin_view, name='adminview'),
url(r'^eventview/$', views.event_view, name='eventview'),
]
In the template, you should use quotes when the url pattern name is a string:
{% url 'adminview' %}
{% url 'eventview' %}
If you want to use namespaces, then app_name should be lowercase.
app_name = 'website'
url_patterns = [
...
]
You then need to include the namespace when you use the url tag
{% url 'website:adminview' %}
{% url 'website:eventview' %}
**Change url to path if you have django version 2.0 **
in URLpatterns, make the change from {} to [] that will solve