I tried all steps and commands to enable the static part when project deployed on Cpanel python app but I failed. Please help me out. Thanks in advance.
Deployed:
Deployed my codes on Cpanel on goDaddy
Images which are visible are from imported from the Internet not from static file
Expected: (On local machine)
I'm able to open each tab in local but getting 404 error on deployed one.
views.py
from django.shortcuts import render, redirect
from django.contrib import messages
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from .forms import ManuForm
def home(request):
if request.method == 'GET':
return render(request, 'manufacture_page/homepage.html', {'form': ManuForm()})
else:
try:
form = ManuForm(request.POST)
if form.is_valid():
form.save(commit=True)
messages.info(request, 'Thanks! Will contact you back.')
return redirect(request.META['HTTP_REFERER'])
else:
print("IN ERROR")
errmsg= str(form.errors)
print(errmsg)
if "Phone already exists" in errmsg:
errmsg="Error!! Entered Number already exists!"
elif "Enter a valid phone number" in errmsg:
errmsg="Error!! Enter number with country code. (e.g. +917529984220)."
else:
errmsg="Error!! Bad data passed in!"
messages.error(request,errmsg)
# return render(request.META['HTTP_REFERER'], 'homepage.html', {'form': ManuForm(), 'error': errmsg})
return redirect(request.META['HTTP_REFERER'], {'form': ManuForm(), 'error': errmsg})
return redirect(home)
except ValueError:
return render(request, 'manufacture_page/homepage.html', {'form': ManuForm(), 'error':'Bad data passed in!'})
def about(request):
return render(request, 'manufacture_page/about.html')
def services(request):
return render(request, 'manufacture_page/services.html')
settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '2dh-pafar$e$te&(m)b^z&yif035l1q=gid!q%$*+#l6r*&%*x'
DEBUG = False
ALLOWED_HOSTS = ['prezotech.in']
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'manufacture_page',
'phonenumber_field',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'lable_manufacturer.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'lable_manufacturer.wsgi.application'
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATICFILES_DIRS=[BASE_DIR+"/static"]
STATIC_URL = '/static/'
STATIC_ROOT= os.path.join(BASE_DIR, 'static')
urls.py
from django.contrib import admin
from django.urls import path
from manufacture_page import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
path('homepage.html', views.home),
path('about.html', views.about),
path('services.html', views.services),
path('homepage.html#newsletter', views.home),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
homepage.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Bootstrap CSS -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp"
crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.css" />
<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="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="{% static "/manufacture_page/style.css" %}">
<link href="https://fonts.googleapis.com/css?family=Lato&display=swap" rel="stylesheet">
<link rel="icon" type="image/png" href="{% static "/manufacture_page/logo.png" %}">
<title>Label manufacturer</title>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-dark bg-dark fixed-top">
<div class="container">
<!-- logo -->
<a href="" class="navbar-brand">
<img src="https://i.ibb.co/523F1fP/poster5-20-12359-1.png" width="45" height="35">
</a>
Prezotech
<a href="https://api.whatsapp.com/send?phone=917529984220" style="font-size:17px;color:grey">
<!-- Send Message</a>-->
<!-- <a href="whatsapp://send?text=Hello World!&phone=+917529984220">-->
<!-- <i class="fa fa-whatsapp style="font-size:22px;color:blue" " aria-hidden="true"></i>-->
Send Msg <i class="fa fa-whatsapp" style="font-size:23px;color:#25D366; "></i>
</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
Home
</li>
<li class="nav-item">
About Us
</li>
<li class="nav-item">
Products & Services
</li>
<li class="nav-item">
Connect with Us
</li>
</ul>
</div>
</div>
</nav>
<!-- SHOWCASE SLIDER -->
<section id="showcase">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item carousel-image-1 ">
<div class="container">
<div class="carousel-caption d-sm-block text-right mb-5 text-dark">
<h1 class="brown_bk"><span>Contact Us</span></h1>
<p class="lead"><span>
Phone Number:
General Query: +91 9990768844 <br>
Sales Team: +91 9990764567<br>
Manufacturing Team: +91 9990768876<br>
Technical Team: +91 9990768833
</span></p>
Contact Details
</div>
</div>
</div>
<div class="carousel-item carousel-image-2">
<div class="container">
<div class="carousel-caption d-sm-block mb-5">
<h1 class="brown_bk"><span>Reviews</span></h1>
<p class="lead"><span>We have the most satisfied customers.
Check out customers review in different sites.</span></p>
<a target="_blank" href="https://www.google.com/search?safe=active&tbm=lcl&sxsrf=ALeKk01Q1Rq0ZRY_DswG94FRSh3b8_7qFg%3A1591739597842&ei=zQTgXs_3Mt_S1fAP3OakmAo&q=prezotech+solutions+private+limited&oq=Prezotech+sol&gs_l=psy-ab.3.0.35i39k1l2j0.878.1332.0.2388.4.4.0.0.0.0.128.386.3j1.4.0....0...1c.1.64.psy-ab..0.4.386...0i30k1.0.a1stxb_bjpo#rlfi=hd:;si:17620352125786189722,l,CiNwcmV6b3RlY2ggc29sdXRpb25zIHByaXZhdGUgbGltaXRlZEjUysywg6uAgAhaWgojcHJlem90ZWNoIHNvbHV0aW9ucyBwcml2YXRlIGxpbWl0ZWQQABABEAIQAxgAGAEYAhgDIiNwcmV6b3RlY2ggc29sdXRpb25zIHByaXZhdGUgbGltaXRlZA;mv:[[28.633411,77.31693310000001],[28.629303200000003,77.31207959999999]]"
class="btn btn-primary btn-sm"> Google</a>
<a target="_blank" href="https://www.justdial.com/Delhi/Prezotech-Solutions-Pvt-Ltd-Near-Nexa-Maruti-Showroom-Ghazipur/011PXX11-XX11-171218141608-Q5M6_BZDET/reviews/page-20?xid=THVkaGlhbmEgV292ZW4gTGFiZWwgTWFudWZhY3R1cmVycyBMb2xheQ=="
class="btn btn-primary btn-sm"> JustDial</a>
<a target="_blank" href="https://www.indiamart.com/prezotech/testimonial.html"
class="btn btn-primary btn-sm"> IndiaMart</a>
<a target="_blank" href="https://www.facebook.com/Prezotech/reviews/?ref=page_internal"
class="btn btn-primary btn-sm"> Facebook</a>
</div>
</div>
</div>
<div class="carousel-item carousel-image-3 active">
<div class="container">
<div class="carousel-caption d-sm-block text-right mb-5">
<h1 class="brown_bk"><span>Prezotech Label Manufacturer</span></h1>
<p class="lead"><span>Leader in the field of label manufacturing and Barcode related solution provider.</span></p>
Learn More About Us
</div>
</div>
</div>
</div>
<a href="#myCarousel" data-slide="prev" class="carousel-control-prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a href="#myCarousel" data-slide="next" class="carousel-control-next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</section>
<!--HOME ICON SECTION -->
<section id="home-icons" class="py-5">
<div class="container">
<div class="row">
<div class="col-md-4 mb-4 text-center">
<i class="fas fa-handshake fa-3x mb-2"></i>
<h3><b>TRUST!</b></h3>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Libero, veniam.</p>
</div>
<div class="col-md-4 mb-4 text-center">
<i class="fas fa-user-lock fa-3x mb-2"></i>
<h3><b>COMMITMENT!</b></h3>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Libero, veniam.</p>
</div>
<div class="col-md-4 mb-4 text-center">
<i class="fas fa-thumbs-up fa-3x mb-2"></i>
<h3><b>QUALITY!</b></h3>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Libero, veniam.</p>
</div>
</div>
</div>
</section>
<!-- HOME HEADING SECTION -->
<section id="home-heading" class="p-5">
<div class="dark-overlay">
<div class="row">
<div class="col">
<div class="container pt-5">
<h1>Our Motto: Customer First!</h1>
<p class="d-none d-md-block">
"Happy customers are your biggest advocates and can become your most successful sales team."
</p>
</div>
</div>
</div>
</div>
</section>
<!-- INFO SECTION -->
<section id="info" class="py-3">
<div class="container">
<div class="row">
<div class="col-md-6 align-self-center">
<h3>Our Team is Our Family!</h3>
<p>With a bunch of experienced team members and Japanese machines we deliver standard and on time
label with any size demanded.</p>
Learn More
</div>
<div class="col-md-6">
<img src="{% static "/manufacture_page/label.gif" %}" alt="" class="img-fluid">
</div>
</div>
</div>
</section>
<!-- VIDEO PLAY -->
<section id="video-play">
<div class="dark-overlay">
<div class="row">
<div class="col">
<div class="container p-5">
<a href="#" class="video" data-video="https://www.youtube.com/embed/cafgEkr2wcc" data-toggle="modal" data-target="#videoModal">
<i class="fas fa-play fa-3x"></i>
</a>
<h1>See What We Do</h1>
</div>
</div>
</div>
</div>
</section>
<!-- PHOTO GALLERY -->
<section id="gallery" class="py-5">
<div class="container">
<h1 class="text-center">Photo Gallery</h1>
<p class="text-center">Check out our photos</p>
<div class="row mb-4">
<div class="col-md-4">
<a href="{% static "/manufacture_page/one.jpg" %}" data-toggle="lightbox" data-gallery="img-gallery" data-height="560"
data-width="560">
<img src="{% static "/manufacture_page/one.jpg" %}" alt="" class="img-fluid">
</a>
</div>
<div class="col-md-4">
<a href="{% static "/manufacture_page/two.png" %}" data-toggle="lightbox" data-gallery="img-gallery" data-height="561"
data-width="561">
<img src="{% static "/manufacture_page/two.png" %}" alt="" class="img-fluid">
</a>
</div>
<div class="col-md-4">
<a href="{% static "/manufacture_page/three.jpg" %}" data-toggle="lightbox" data-gallery="img-gallery" data-height="562"
data-width="562">
<img src="{% static "/manufacture_page/three.jpg" %}" alt="" class="img-fluid">
</a>
</div>
</div>
<div class="row mb-4">
<div class="col-md-4">
<a href="{% static "/manufacture_page/four.jpg" %}" data-toggle="lightbox" data-gallery="img-gallery" data-height="563"
data-width="563">
<img src="{% static "/manufacture_page/four.jpg" %}" alt="" class="img-fluid">
</a>
</div>
<div class="col-md-4">
<a href="{% static "/manufacture_page/five.png" %}" data-toggle="lightbox" data-gallery="img-gallery" data-height="564"
data-width="564">
<img src="{% static "/manufacture_page/five.png" %}" alt="" class="img-fluid">
</a>
</div>
<div class="col-md-4">
<a href="{% static "/manufacture_page/six.jpeg" %}" data-toggle="lightbox" data-gallery="img-gallery" data-height="565"
data-width="565">
<img src="{% static "/manufacture_page/six.jpeg" %}" alt="" class="img-fluid">
</a>
</div>
</div>
</div>
</section>
<!-- NEWSLETTER -->
<section id="newsletter" class="text-center p-5 bg-dark text-white">
<div class="container">
<div class="row">
<div class="col">
<div class ="newsletter1 {% if active_tab == 'newsletter1' %} active{% endif %}">
<label><h1>Get In Touch</h1></label>
<!-- <h2>{{ error }}</h2>-->
{% for message in messages %}
<div class="alert alert-success">
<a class="close" href="#" data-dismiss="alert">×</a>
<h6> {{ message }} </h6>
</div>
{% endfor %}
<form method="POST" class="form-inline justify-content-center">
{% csrf_token %}
<input type="text" name="name" class="form-control mb-2 mr-2" placeholder="Enter Name" id="name" required>
<input type="tel" name="phone" class="form-control mb-2 mr-2" placeholder="Enter Phone" id="phone" required>
<input type="email" name="email" class="form-control mb-2 mr-2" placeholder="Enter Email" id="email" >
<input type="text" name="query" class="form-control mb-2 mr-2" placeholder="Any Query?" id="query">
<button class="btn btn-primary mb-2" type="submit">Send</button>
</form>
</div>
<br>
<!-- Social media-->
<li class="nav-item ml-auto active">
<a href="https://www.prezotech.com/" class="nav-link" >
<input type="image" src="https://i.ibb.co/kchdgsK/poster5-23-205140-1.png" />
</a>
</li>
<li class="nav-item ml-auto">
<i class="fab fa-instagram" style="font-size:32px;color:red"></i>
</li>
<li class="nav-item ml-auto">
<i class="fab fa-youtube" style="font-size:32px;color:red" ></i>
</li>
<li class="nav-item ml-auto">
<i class="fab fa-facebook-f" style="font-size:27px;color:blue" ></i>
</li>
<li class="nav-item ml-auto">
<i class="fa fa-linkedin" style="font-size:29px;color:blue" ></i>
</li>
<li class="nav-item ml-auto">
<i class="fa fa-twitter" style="font-size:29px;color:blue" ></i>
</li>
<li class="nav-item ml-auto">
<i class="fas fa-comment-dots" style="font-size:29px;color:purple" ></i>
</li>
</div>
</div>
</div>
</section>
<!-- FOOTER -->
<footer id="main-footer" class="text-center p-4">
<div class="container">
<div class="row">
<div class="col">
<p>Copyright ©
<span id="year"></span> Prezotech</p>
</div>
</div>
</div>
</footer>
<!-- VIDEO MODAL -->
<div class="modal fade" id="videoModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<button class="close" data-dismiss="modal">
<span>×</span>
</button>
<iframe src="" frameborder="0" height="350" width="100%" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.min.js"></script>
<script>
// Get the current year for the copyright
$('#year').text(new Date().getFullYear());
// Configure Slider
$('.carousel').carousel({
interval: 6000,
pause: 'hover'
});
// Lightbox Init
$(document).on('click', '[data-toggle="lightbox"]', function (event) {
event.preventDefault();
$(this).ekkoLightbox();
});
// Video Play
$(function () {
// Auto play modal video
$(".video").click(function () {
var theModal = $(this).data("target"),
videoSRC = $(this).attr("data-video"),
videoSRCauto = videoSRC + "?modestbranding=1&rel=0&controls=0&showinfo=0&html5=1&autoplay=1";
$(theModal + ' iframe').attr('src', videoSRCauto);
$(theModal + ' button.close').click(function () {
$(theModal + ' iframe').attr('src', videoSRC);
});
});
});
</script>
</body>
</html>
Directory structure
enter link description here
P.S: I have already used collectstatic
Run this command to build all the static files:
python manage.py collectstatic
After this, a static folder containing all the required static files will be created at the project root. Just upload that folder onto cPanel and paste the URL back in your Django app.
Related
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>
The django 'extends' template is not loading the content. In this I am trying to extend index.html to homepage.html. Both the files are under the same templates directory. The code snippets are shown below:
index.html
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Tashi eComm</title>
<!-- adding title icon -->
<link rel = "icon" href ="{% static 'images/TecommLogo.png' %}" type = "image/x-icon">
<!-- Bootstrap 5 link -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<!-- Bootstrap 5 popper and javascript link -->
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.9.3/dist/umd/popper.min.js" integrity="sha384-W8fXfP3gkOKtndU4JGtKDvXbO53Wy8SZCQHczT5FMiiqmQfUpWbYdTil/SxwZgAN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/js/bootstrap.min.js" integrity="sha384-skAcpIdS7UcVUC05LJ9Dxay8AXcDYfBJqt1CJ85S/CFujBsIzCIv+l9liuYLaMQ/" crossorigin="anonymous"></script>
<!--Bootstrap icons-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.5.0/font/bootstrap-icons.css">
<!-- stylesheet -->
<link rel="stylesheet" type="text/css" href="{% static 'css/stylesheet.css' %}"/>
</head>
<body>
<div class="wrapper">
<div class="panel panel-default">
<div class="panel-heading">
<div class="d-flex justify-content-end ">
<div class="top-header m-2 ">
Marketplace
</div>
<div class="top-header m-2 ">|</div>
<div class="top-header m-2">
Buyer Protection
</div>
<div class="top-header m-2 ">|</div>
<div class="top-header m-2">
Track Order
</div>
<div class="top-header m-2 ">|</div>
<div class="top-header m-2">
<div class="form-group">
<select id="demo_overview_minimal" class="select-picker" data-role="select-dropdown" data-profile="minimal">
<!-- options -->
<option>BTN</option>
<option>USD</option>
<option>EUR</option>
</select>
</div>
</div>
</div>
</div>
<div class="panel-body">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand ms-5" href="#"><img src="{% static 'images/TecommLogo.png' %}" alt="Logo" height="60px" width="60px"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Shop by Category
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
<form class="d-flex Search col-5">
<input class="form-control me-auto col-8" type="search" placeholder="Search for anything" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
{% block content %}
{% endblock content%}
<footer>
<div class="panel panel-default">
<div class="panel-footer bg-light ">
<div class="row ms-5 me-5">
<div class="col-sm-3">
<div class="row">
<h3>Policies</h3>
</div>
<div class="row">
Privacy Policies
</div>
<div class="row">
Refund Policies
</div>
<div class="row">
Terms & Conditions
</div>
</div>
<div class="col-sm-3">
<div class="row">
<h3>Vendor</h3>
</div>
<div class="row">
Start Selling
</div>
<div class="row">
Learn to Sell
</div>
</div>
<div class="col-sm-3">
<div class="row">
<h3>Connect With Us</h3>
</div>
<div class="row">
<i class="bi bi-facebook"></i>Facebook
</div>
<div class="row">
<i class="bi bi-twitter"></i>Twiiter
</div>
<div class="row">
<i class="bi bi-instagram"></i>Instagram
</div>
</div>
<div class="col-sm-3">
<div class="row">
<h3>Help & Contact</h3>
</div>
<div class="row">
Contact
</div>
<div class="row">
About Us
</div>
<div class="row">
FAQs
</div>
</div>
</div>
</div>
</div>
</footer>
</div>
</body>
</html>
homepage.html
{% extends 'index.html' %}
{% block content %}
Hello! this is my block content
{% endblock content %}
urls.py
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import path, include
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.homepage, name="homepage"),
# path('accounts/', include('accounts.urls')),
]
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
views.py
from django.shortcuts import render
def homepage(request):
return render(request, 'index.html')
I have done the similar projects earlier but it was working fine. I don't know why it doesn't work in this project while i have done everything similar
I have been trying this for a whole day. Any help will be appreciated.
You want to extend index.html to homepage.html so you have to call homepage.html in your views.py file.
from django.shortcuts import render
def homepage(request):
return render(request, 'homepage.html')
"""
codes in settings.py
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*-by0qr_kjdy8soie*gt*lg0vo+pc(1#34b5g-q1e=uv5%phzt'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'travello.apps.TravelloConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'telusko.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'telusko.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
MEDIA_ROOT = '/static/images/media'
MEDIA_URL = '/media/'
Added bellow code but still it has not solved
MEDIA_ROOT = '/static/images/media'
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
STATICFILES_DIR = [
os.path.join(BASE_DIR,'static')
]
STATIC_ROOT = os.path.join(BASE_DIR,'assets')
I have added bootstrap template to my Django project. I am facing the problem with the images are not getting load when check index.html in local host, when I inspect the html code it's showing error like this "GET /images/destination_4.jpg HTTP/1.1" 404 2300" while All other static files are getting loaded. I have ensured that the presense of 'django.contrib.staticfiles', in installed app, also added STATIC_DIR and STATIC_ROOT in settings.py and in html page static files are loaded. Please let me know the solution. I have added index.html code and STATIC_URL below.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Travello</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Travello template project">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'styles/bootstrap4/bootstrap.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'plugins/font-awesome-4.7.0/css/font-awesome.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'plugins/OwlCarousel2-2.2.1/owl.carousel.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'plugins/OwlCarousel2-2.2.1/owl.theme.default.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'plugins/OwlCarousel2-2.2.1/animate.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'styles/main_styles.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'styles/responsive.css' %}">
</head>
<body>
<div class="super_container">
<!-- Header -->
<header class="header">
<div class="container">
<div class="row">
<div class="col">
<div class="header_content d-flex flex-row align-items-center justify-content-start">
<div class="header_content_inner d-flex flex-row align-items-end justify-content-start">
<div class="logo">Travello</div>
<nav class="main_nav">
<ul class="d-flex flex-row align-items-start justify-content-start">
<li class="active">Home</li>
<li>About us</li>
<li>Services</li>
<li>News</li>
<li>Contact</li>
</ul>
</nav>
<div class="header_phone ml-auto">Call us: 00-56 445 678 33</div>
<!-- Hamburger -->
<div class="hamburger ml-auto">
<i class="fa fa-bars" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="header_social d-flex flex-row align-items-center justify-content-start">
<ul class="d-flex flex-row align-items-start justify-content-start">
<li><i class="fa fa-pinterest" aria-hidden="true"></i></li>
<li><i class="fa fa-facebook" aria-hidden="true"></i></li>
<li><i class="fa fa-twitter" aria-hidden="true"></i></li>
<li><i class="fa fa-dribbble" aria-hidden="true"></i></li>
<li><i class="fa fa-behance" aria-hidden="true"></i></li>
<li><i class="fa fa-linkedin" aria-hidden="true"></i></li>
</ul>
</div>
</header>
<!-- Menu -->
<div class="menu">
<div class="menu_header d-flex flex-row align-items-center justify-content-start">
<div class="menu_logo">Travello</div>
<div class="menu_close_container ml-auto"><div class="menu_close"><div></div><div></div></div></div>
</div>
<div class="menu_content">
<ul>
<li>Home</li>
<li>About us</li>
<li>Services</li>
<li>News</li>
<li>Contact</li>
</ul>
</div>
<div class="menu_social">
<div class="menu_phone ml-auto">Call us: 00-56 445 678 33</div>
<ul class="d-flex flex-row align-items-start justify-content-start">
<li><i class="fa fa-pinterest" aria-hidden="true"></i></li>
<li><i class="fa fa-facebook" aria-hidden="true"></i></li>
<li><i class="fa fa-twitter" aria-hidden="true"></i></li>
<li><i class="fa fa-dribbble" aria-hidden="true"></i></li>
<li><i class="fa fa-behance" aria-hidden="true"></i></li>
<li><i class="fa fa-linkedin" aria-hidden="true"></i></li>
</ul>
</div>
</div>
<!-- Home -->
<div class="home">
<!-- Home Slider -->
<div class="home_slider_container">
<div class="owl-carousel owl-theme home_slider">
<!-- Slide -->
<div class="owl-item">
<div class="background_image" style="background-image: url(images/home_slider.jpg)"></div>
<div class="home_slider_content_container">
<div class="container">
<div class="row">
<div class="col">
<div class="home_slider_content">
<div class="home_title"><h2>Let us take you away</h2></div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Slide -->
<div class="owl-item">
<div class="background_image" style="background-image:url(images/home_slider.jpg)"></div>
<div class="home_slider_content_container">
<div class="container">
<div class="row">
<div class="col">
<div class="home_slider_content">
<div class="home_title"><h2>Let us take you away</h2></div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Slide -->
<div class="owl-item">
<div class="background_image" style="background-image:url(images/home_slider.jpg)"></div>
<div class="home_slider_content_container">
<div class="container">
<div class="row">
<div class="col">
<div class="home_slider_content">
<div class="home_title"><h2>Let us take you away</h2></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="home_page_nav">
<ul class="d-flex flex-column align-items-end justify-content-end">
<li>Offers<span>01</span></li>
<li>Testimonials<span>02</span></li>
<li>Latest<span>03</span></li>
</ul>
</div>
</div>
</div>
<!-- Search -->
<div class="home_search">
<div class="container">
<div class="row">
<div class="col">
<div class="home_search_container">
<div class="home_search_title">Search for your trip</div>
<div class="home_search_content">
<form action="#" class="home_search_form" id="home_search_form">
<div class="d-flex flex-lg-row flex-column align-items-start justify-content-lg-between justify-content-start">
<input type="text" class="search_input search_input_1" placeholder="City" required="required">
<input type="text" class="search_input search_input_2" placeholder="Departure" required="required">
<input type="text" class="search_input search_input_3" placeholder="Arrival" required="required">
<input type="text" class="search_input search_input_4" placeholder="Budget" required="required">
<button class="home_search_button">search</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Intro -->
<div class="intro">
<div class="intro_background" style="background-image:url(images/intro.png)"></div>
<div class="container">
<div class="row">
<div class="col">
<div class="intro_container">
<div class="row">
<!-- Intro Item -->
<div class="col-lg-4 intro_col">
<div class="intro_item d-flex flex-row align-items-end justify-content-start">
<div class="intro_icon"><img src="images/beach.svg" alt=""></div>
<div class="intro_content">
<div class="intro_title">Top Destinations</div>
<div class="intro_subtitle"><p>Nulla pretium tincidunt felis, nec.</p></div>
</div>
</div>
</div>
<!-- Intro Item -->
<div class="col-lg-4 intro_col">
<div class="intro_item d-flex flex-row align-items-end justify-content-start">
<div class="intro_icon"><img src="images/wallet.svg" alt=""></div>
<div class="intro_content">
<div class="intro_title">The Best Prices</div>
<div class="intro_subtitle"><p>Sollicitudin mauris lobortis in.</p></div>
</div>
</div>
</div>
<!-- Intro Item -->
<div class="col-lg-4 intro_col">
<div class="intro_item d-flex flex-row align-items-end justify-content-start">
<div class="intro_icon"><img src="images/suitcase.svg" alt=""></div>
<div class="intro_content">
<div class="intro_title">Amazing Services</div>
<div class="intro_subtitle"><p>Nulla pretium tincidunt felis, nec.</p></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Destinations -->
<div class="destinations" id="destinations">
<div class="container">
<div class="row">
<div class="col text-center">
<div class="section_subtitle">simply amazing places</div>
<div class="section_title"><h2>Popular Destinations</h2></div>
</div>
</div>
<div class="row destinations_row">
<div class="col">
<div class="destinations_container item_grid">
<!-- Destination -->
<div class="destination item">
<div class="destination_image">
<img src="images/destination_1.jpg" alt="">
<div class="spec_offer text-center">Special Offer</div>
</div>
<div class="destination_content">
<div class="destination_title">Bali</div>
<div class="destination_subtitle"><p>Nulla pretium tincidunt felis, nec.</p></div>
<div class="destination_price">From $679</div>
</div>
</div>
<!-- Destination -->
<div class="destination item">
<div class="destination_image">
<img src="images/destination_2.jpg" alt="">
</div>
<div class="destination_content">
<div class="destination_title">Indonesia</div>
<div class="destination_subtitle"><p>Nulla pretium tincidunt felis, nec.</p></div>
<div class="destination_price">From $679</div>
</div>
</div>
<!-- Destination -->
<div class="destination item">
<div class="destination_image">
<img src="images/destination_3.jpg" alt="">
</div>
<div class="destination_content">
<div class="destination_title">San Francisco</div>
<div class="destination_subtitle"><p>Nulla pretium tincidunt felis, nec.</p></div>
<div class="destination_price">From $679</div>
</div>
</div>
<!-- Destination -->
<div class="destination item">
<div class="destination_image">
<img src="images/destination_4.jpg" alt="">
</div>
<div class="destination_content">
<div class="destination_title">Paris</div>
<div class="destination_subtitle"><p>Nulla pretium tincidunt felis, nec.</p></div>
<div class="destination_price">From $679</div>
</div>
</div>
<!-- Destination -->
<div class="destination item">
<div class="destination_image">
<img src="images/destination_5.jpg" alt="">
</div>
<div class="destination_content">
<div class="destination_title">Phi Phi Island</div>
<div class="destination_subtitle"><p>Nulla pretium tincidunt felis, nec.</p></div>
<div class="destination_price">From $679</div>
</div>
</div>
<!-- Destination -->
<div class="destination item">
<div class="destination_image">
<img src="images/destination_6.jpg" alt="">
</div>
<div class="destination_content">
<div class="destination_title">Mykonos</div>
<div class="destination_subtitle"><p>Nulla pretium tincidunt felis, nec.</p></div>
<div class="destination_price">From $679</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Testimonials -->
<div class="testimonials" id="testimonials">
<div class="parallax_background parallax-window" data-parallax="scroll" data-image-src="images/testimonials.jpg" data-speed="0.8"></div>
<div class="container">
<div class="row">
<div class="col text-center">
<div class="section_subtitle">simply amazing places</div>
<div class="section_title"><h2>Testimonials</h2></div>
</div>
</div>
<div class="row testimonials_row">
<div class="col">
<!-- Testimonials Slider -->
<div class="testimonials_slider_container">
<div class="owl-carousel owl-theme testimonials_slider">
<!-- Slide -->
<div class="owl-item text-center">
<div class="testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. lobortis dolor. Cras placerat lectus a posuere aliquet. Curabitur quis vehicula odio.</div>
<div class="testimonial_author">
<div class="testimonial_author_content d-flex flex-row align-items-end justify-content-start">
<div>john turner,</div>
<div>client</div>
</div>
</div>
</div>
<!-- Slide -->
<div class="owl-item text-center">
<div class="testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. lobortis dolor. Cras placerat lectus a posuere aliquet. Curabitur quis vehicula odio.</div>
<div class="testimonial_author">
<div class="testimonial_author_content d-flex flex-row align-items-end justify-content-start">
<div>john turner,</div>
<div>client</div>
</div>
</div>
</div>
<!-- Slide -->
<div class="owl-item text-center">
<div class="testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. lobortis dolor. Cras placerat lectus a posuere aliquet. Curabitur quis vehicula odio.</div>
<div class="testimonial_author">
<div class="testimonial_author_content d-flex flex-row align-items-end justify-content-start">
<div>john turner,</div>
<div>client</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="test_nav">
<ul class="d-flex flex-column align-items-end justify-content-end">
<li>City Breaks Clients<span>01</span></li>
<li>Cruises Clients<span>02</span></li>
<li>All Inclusive Clients<span>03</span></li>
</ul>
</div>
</div>
<!-- News -->
<div class="news" id="news">
<div class="container">
<div class="row">
<div class="col-xl-8">
<div class="news_container">
<!-- News Post -->
<div class="news_post d-flex flex-md-row flex-column align-items-start justify-content-start">
<div class="news_post_image"><img src="images/news_1.jpg" alt=""></div>
<div class="news_post_content">
<div class="news_post_date d-flex flex-row align-items-end justify-content-start">
<div>02</div>
<div>june</div>
</div>
<div class="news_post_title">Best tips to travel light</div>
<div class="news_post_category">
<ul>
<li>lifestyle & travel</li>
</ul>
</div>
<div class="news_post_text">
<p>Pellentesque sit amet elementum ccumsan sit amet mattis eget, tristique at leo. Vivamus massa.Tempor massa et laoreet.</p>
</div>
</div>
</div>
<!-- News Post -->
<div class="news_post d-flex flex-md-row flex-column align-items-start justify-content-start">
<div class="news_post_image"><img src="images/news_2.jpg" alt=""></div>
<div class="news_post_content">
<div class="news_post_date d-flex flex-row align-items-end justify-content-start">
<div>01</div>
<div>june</div>
</div>
<div class="news_post_title">Best tips to travel light</div>
<div class="news_post_category">
<ul>
<li>lifestyle & travel</li>
</ul>
</div>
<div class="news_post_text">
<p>Tempor massa et laoreet malesuada. Pellentesque sit amet elementum ccumsan sit amet mattis eget, tristique at leo.</p>
</div>
</div>
</div>
<!-- News Post -->
<div class="news_post d-flex flex-md-row flex-column align-items-start justify-content-start">
<div class="news_post_image"><img src="images/news_3.jpg" alt=""></div>
<div class="news_post_content">
<div class="news_post_date d-flex flex-row align-items-end justify-content-start">
<div>29</div>
<div>may</div>
</div>
<div class="news_post_title">Best tips to travel light</div>
<div class="news_post_category">
<ul>
<li>lifestyle & travel</li>
</ul>
</div>
<div class="news_post_text">
<p>Vivamus massa.Tempor massa et laoreet malesuada. Aliquam nulla nisl, accumsan sit amet mattis.</p>
</div>
</div>
</div>
</div>
</div>
<!-- News Sidebar -->
<div class="col-xl-4">
<div class="travello">
<div class="background_image" style="background-image:url(images/travello.jpg)"></div>
<div class="travello_content">
<div class="travello_content_inner">
<div></div>
<div></div>
</div>
</div>
<div class="travello_container">
<a href="#">
<div class="d-flex flex-column align-items-center justify-content-end">
<span class="travello_title">Get a 20% Discount</span>
<span class="travello_subtitle">Buy Your Vacation Online Now</span>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer class="footer">
<div class="parallax_background parallax-window" data-parallax="scroll" data-image-src="images/footer_1.jpg" data-speed="0.8"></div>
<div class="container">
<div class="row">
<div class="col">
<div class="newsletter">
<div class="newsletter_title_container text-center">
<div class="newsletter_title">Subscribe to our newsletter to get the latest trends & news</div>
<div class="newsletter_subtitle">Join our database NOW!</div>
</div>
<div class="newsletter_form_container">
<form action="#" class="newsletter_form d-flex flex-md-row flex-column align-items-start justify-content-between" id="newsletter_form">
<div class="d-flex flex-md-row flex-column align-items-start justify-content-between">
<div><input type="text" class="newsletter_input newsletter_input_name" id="newsletter_input_name" placeholder="Name" required="required"><div class="input_border"></div></div>
<div><input type="email" class="newsletter_input newsletter_input_email" id="newsletter_input_email" placeholder="Your e-mail" required="required"><div class="input_border"></div></div>
</div>
<div><button class="newsletter_button">subscribe</button></div>
</form>
</div>
</div>
</div>
</div>
<div class="row footer_contact_row">
<div class="col-xl-10 offset-xl-1">
<div class="row">
<!-- Footer Contact Item -->
<div class="col-xl-4 footer_contact_col">
<div class="footer_contact_item d-flex flex-column align-items-center justify-content-start text-center">
<div class="footer_contact_icon"><img src="images/sign.svg" alt=""></div>
<div class="footer_contact_title">give us a call</div>
<div class="footer_contact_list">
<ul>
<li>Office Landline: +44 5567 32 664 567</li>
<li>Mobile: +44 5567 89 3322 332</li>
</ul>
</div>
</div>
</div>
<!-- Footer Contact Item -->
<div class="col-xl-4 footer_contact_col">
<div class="footer_contact_item d-flex flex-column align-items-center justify-content-start text-center">
<div class="footer_contact_icon"><img src="images/trekking.svg" alt=""></div>
<div class="footer_contact_title">come & drop by</div>
<div class="footer_contact_list">
<ul style="max-width:190px">
<li>4124 Barnes Street, Sanford, FL 32771</li>
</ul>
</div>
</div>
</div>
<!-- Footer Contact Item -->
<div class="col-xl-4 footer_contact_col">
<div class="footer_contact_item d-flex flex-column align-items-center justify-content-start text-center">
<div class="footer_contact_icon"><img src="images/around.svg" alt=""></div>
<div class="footer_contact_title">send us a message</div>
<div class="footer_contact_list">
<ul>
<li>youremail#gmail.com</li>
<li>Office#yourbusinessname.com</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col text-center"><!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
Copyright ©<script>document.write(new Date().getFullYear());</script> All rights reserved | This template is made with <i class="fa fa-heart-o" aria-hidden="true"></i> by Colorlib
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. --> </div>
</footer>
</div>
<script src="{% static 'js/jquery-3.2.1.min.js' %}"></script>
<script src="{% static 'styles/bootstrap4/popper.js' %}"></script>
<script src="{% static 'styles/bootstrap4/bootstrap.min.js' %}"></script>
<script src="{% static 'plugins/OwlCarousel2-2.2.1/owl.carousel.js' %}"></script>
<script src="{% static 'plugins/Isotope/isotope.pkgd.min.js' %}"></script>
<script src="{% static 'plugins/scrollTo/jquery.scrollTo.min.js' %}"></script>
<script src="{% static 'plugins/easing/easing.js' %}"></script>
<script src="{% static 'plugins/parallax-js-master/parallax.min.js' %}"></script>
<script src="{% static 'js/custom.js' %}"></script>
<style type="text/css">
.background_image {
background-image: url(images/home_slider.jpg);
}
</style>
</body>
</html>
Once again, this log record
GET /images/destination_4.jpg HTTP/1.1" 404 2300
is clearly saying that you're trying to access URL which is not under STATIC_URL address. Since you said that some of files work fine I surmised that config is correct but image URL is not.
Here is an example of well defined static file URL:
<link rel="stylesheet" type="text/css" href="{% static 'styles/bootstrap4/bootstrap.min.css' %}">
here all your Django settings for static files will take effect.
Below is one of the problematic places:
<img src="images/destination_4.jpg" alt="">
static template tag is not used here thus this is just a constant URL. Moreover, this is relative URL (because it does not start with /) and will result in different absolute URL on different pages. Fix this, start using static template tag here and images will load just fine (if they exist in specified folder).
One more thing which is perhaps the cause of other problems:
you defined MEDIA_ROOT as /static/images/media which is inside static files folder. That is not really a good idea. Note, media files in Django mean dynamic, editable files uploaded by users. If an image or a video is a part of your solution (like logo, favicon, backround image) - they are not "media" in terms of Django - they are "static" files. Yes, you can put them into separate subfolder just like any .js or .css files - but they will remain static and you have to work with them like with other static files.
You should not mix media files with static inside one directory because you will be overwriting static folder from time to time during deployment of new releases of your Django project.
Problem solved!
Thanks to Ivan Starostin. He suggested to to add static tag to all images, I followed his instruction made changes now the code is working.
Before changes class="background_image" style="background-image:url(images/home_slider.jpg)"></div>
After changes <div class="background_image" style="background-image: url({% static 'images/home_slider.jpg' %})"></div>
I have installed Django-allauth on my site,
I made a modal with both login and signup in it,
the login and signup works ok (doh I have a problem that if the login isn't good it just freezes at a white page)
the problem is that under login, I have a forgot your password button,
but once clicked it redirect to http://127.0.0.1:8000/accounts/password/reset/,
but online show a white page, like the allauth templates, were not loaded
URLs
path('users/', include('users.urls')), #for allauth
url(r'^accounts/', include('allauth.urls')), #custom user
SETTINGS:
INSTALLED_APPS = [
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
AUTH_USER_MODEL = 'users.CustomUser'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
"allauth.account.auth_backends.AuthenticationBackend",
)
TEMPLATES ... # `allauth` needs this from django
'django.template.context_processors.request',
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_LOGIN_ATTEMPTS_LIMIT =5
ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT =1800
ACCOUNT_USERNAME_BLACKLIST =[]
ACCOUNT_UNIQUE_EMAIL =True
this is the button for forgotten password
<div>
<a class="forgotpass" href="{% url 'account_reset_password' %}">
{% trans "Forgot Password?" %}</a>
</div>
What did I do wrong ??
UPON REQUEST HERE IS THE WEBSITE BASE TEMPLATE:
<!DOCTYPE html>
<html lang="zxx" class="no-js">
{% load static from static %} {% load socialaccount %}{% load i18n %}
<head>
<!-- Mobile Specific Meta -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Favicon-->
<link rel="shortcut icon" href='{% static "/home/img/favicon.ico" %}'>
<!-- Meta Description -->
<meta name="description" content="">
<!-- Meta Keyword -->
<meta name="keywords" content="">
<!-- meta character set -->
<meta charset="UTF-8">
<!-- Title -->
<title>Dr.Landivar</title>
<link href="https://fonts.googleapis.com/css?family=Poppins:100,200,400,300,500,600,700" rel="stylesheet">
<!-- CSS -->
{% block css %}
{% endblock %}
<style>
.footer-social {
font-size: 1rem !important;
}
.comment {
margin: 20px 0px 20px 20px;
}
.banner-area {
background: url('{% static "/home/img/banner-bg.jpg" %}') no-repeat center;
}
.home-about-area:after {
background: url('{% static "/home/img/about-img.jpg" %}') no-repeat center center/cover;
}
.appoinment-area:after {
background: url('{% static "/home/img/appoinment-img.jpg" %}') no-repeat center center/cover;
}
.about-banner {
background: url('{% static "/home/img/top-banner.jpg" %}') center
}
.blog-home-banner {
background: url('{% static "/home/img/-blog/blog-home-banner.jpg" %}') bottom;
}
</style>
<script src="https://use.fontawesome.com/d2f653f275.js"></script>
</head>
<body>
<!-- Start header Area -->
<header id="header" id="home">
<div class="header-top">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-6 col-sm-6 col-4 header-top-left no-padding">
<a href="/">
<img src='{% static "/home/img/logo.png" %}' alt="" title="" />
</a>
</div>
<div class="col-lg-6 col-sm-6 col-8 header-top-right no-padding specialwidthphone">
<a class="btns" href="tel:+010101010">+1 050505050</a>
<a class="icons" href="tel:+953 012 3654 896">
<span class="lnr lnr-phone-handset"></span>
</a>
</div>
</div>
</div>
</div>
<div class="container main-menu">
<div class="row align-items-center justify-content-between d-flex">
<nav id="nav-menu-container">
<ul class="nav-menu">
<li>
Blog
</li>
<li>
{% trans "Videos" %}
</li>
<li>
{% trans "Online Appointments" %}
</li>
<li>
{% trans "Contact Us" %}
</li>
<li>
{% trans "Shop Online" %}
</li>
<li>
<a href="/cart">
<i class="fa fa-shopping-cart fa-2x" aria-hidden="true"></i>
</a>
</li>
<li id="sign-in">
{% if user.is_authenticated %}
<p id="welcome">{% trans "Welcome" %} {{ user.username }}</p>
<a id="dash" href="/dash">
<i class="fa fa-tachometer" aria-hidden="true"></i>
</a>
<a id="log" href="{% url 'account_logout' %}">
<i class="fa fa-sign-out" aria-hidden="true"></i>
</a>
<p>
{% else %}
<!-- Button to Open the Modal -->
<div class="loginbtn">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
{% trans "Login" %}
</button>
</div>
<div class="modal-login">
<!-- The Modal For LOGIN -->
<div class="modal fade" id="myModal">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<!-- LOGIN Modal Header -->
<div class="modal-header">
<h3 class="modal-title">{% trans "Login" %}</h3>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- LOGIN Modal body -->
<div class="modal-body">
<form action="{% url 'account_login' %}" method="post">
{% csrf_token %}
<input type="hidden" name="next" value="{{ request.get_full_path }}" />
<label class="login" for="id_login">{% trans "Username or email:" %} </label>
<input id="id_login" name="login" placeholder="Username or e-mail" type="text" required />
<div>
<label class="password" for="id_password">{% trans "Password:" %} </label>
<input id="id_password" name="password" placeholder="Password" type="password" required />
</div>
<label class="remember" for="id_remember">{% trans "Remember Me:" %}</label>
<input id="id_remember" name="remember" type="checkbox" />
<div>
<button class="submit-btn btn btn-success btn-sm" type="submit">{% trans "Login" %}</button>
</div>
<div>
<a class="forgotpass" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
</div>
</form>
<hr id="line">
<form action="{% url 'account_signup' %}" method="post">
{% csrf_token %}
<h4 class="signinhere">{% trans "You are not signed in yet ? Sign in here" %}</h4>
<input type="hidden" name="next" value="{{ request.get_full_path }}" />
<label class="user" for="id_username">{% trans "Username:" %} </label>
<input id="id_username" name="username" placeholder="Username" type="text" required />
<div>
<label class="email" for="id_email">{% trans "E-mail:" %}</label>
<input type="email" name="email" placeholder="E-mail address" required id="id_email">
</div>
<label class="pass1" for="id_password1">{% trans "Password:" %}</label>
<input type="password" name="password1" placeholder="Password" required id="id_password1">
<div>
<label class="pass2" for="id_password2">{% trans "Password (again):" %}</label>
<input type="password" name="password2" placeholder="Password (again)" required id="id_password2">
</div>
<div>
<button class="submit-btn btn btn-success btn-sm" type="submit">{% trans "Submit" %}</button>
</div>
</form>
</div>
<!-- LOGIN Modal footer -->
<div class="modal-footer">
<div>
<p class="specialgmail">
<i class="fab fa-google"></i>
<a id="gmail" href="{% provider_login_url 'google' %}">{% trans "Log In with Gmail" %}</a>
</p>
</div>
<button type="button" class="icon-right btn btn-danger" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
</div>
</div>
</div>
</p>
{% endif %}
</p>
</li>
</ul>
</nav>
</div>
</div>
</header>
<!-- End header Area -->
{% block content %}
{% endblock%}
<!-- start footer Area -->
<footer class="footer-area section-gap">
<div class="container">
<div class="row">
<div class="col-lg-2 col-md-6">
<div class="single-footer-widget">
<h6>{% trans "Navigate" %}</h6>
<ul class="footer-nav">
<li>
{% trans "Log In or Register" %}
</li>
<li>
{% trans "Help Center" %}
</li>
<li>
{% trans "Shipping Policy" %}
</li>
<li>
{% trans "Terms of Service" %}
</li>
</ul>
</div>
</div>
<div class="col-lg-4 col-md-6">
<div class="single-footer-widget mail-chimp">
<h6 class="mb-20">{% trans "Contact Us" %}</h6>
<p>
{% trans "2060 Biscayne Blvd, Miami, FL 33137, EE. UU." %}
</p>
<h3>012-6532-568-9746</h3>
<h3>012-6532-568-97468</h3>
</div>
</div>
<div class="col-lg-6 col-md-12">
<div class="single-footer-widget newsletter">
<h6>{% trans "Newsletter" %}</h6>
<p>{% trans "You can trust us. we only send promo offers, not a single spam." %}</p>
<div id="mc_embed_signup">
<form action="https://drlandivar.us19.list-manage.com/subscribe/post?u=a988793f3acfebb954fa9a95e&id=da7c864704"
method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank"
novalidate>
<div class="form-group row" style="width: 100%">
<div class="col-lg-8 col-md-12">
<input name="EMAIL" placeholder="Your Email Address" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Your Email Address '"
required="" type="email">
<div style="position: absolute; left: -5000px;">
<input name="b_a988793f3acfebb954fa9a95e_da7c864704" tabindex="-1" value="" type="text">
</div>
</div>
<div class="col-lg-4 col-md-12">
<button class="nw-btn primary-btn">{% trans "Subscribe" %}
<span class="lnr lnr-arrow-right"></span>
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row footer-bottom d-flex justify-content-between">
<p class="col-lg-8 col-sm-12 footer-text m-0">
</p>
<div class="col-lg-4 col-sm-12 footer-social">
<a href="https://www.facebook.com/Dr.Gus.Landivar/" target="_blank">
<i class="fa fa-facebook-square"></i>
</a>
<a href="https://plus.google.com/u/1/112018602499732214904?tab=mX" target="_blank">
<i class="fa fa-google-plus"></i>
</a>
<a href="https://www.youtube.com/channel/UCl8nmbvMhlc5-os-2n7uSQg" target="_blank">
<i class="fa fa-youtube-play"></i>
</a>
</div>
</div>
</div>
</footer>
<!-- End footer Area -->
{% block scripts %}
{% endblock%}
</body>
</html>
You should extend your base.html instead of allauth's base.html
I am new at django and I have an app in django project. My base.html has navigation bar through which you can redirect to "about", 'contact us', 'home'.
The first page when app starts (after loging in) is home.
<!DOCTYPE html>
<html lang="en">
<head>
{%load staticfiles%}
<meta charset="utf-8">
<title>Ekyam: India's First Entrepreneurial Ecosystem</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta content="" name="keywords">
<meta content="" name="description">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700,900" rel="stylesheet">
<!-- Bootstrap CSS File -->
<link href="{% static "visit/lib/bootstrap/css/bootstrap.min.css" %}" rel="stylesheet">
<!-- Libraries CSS Files -->
<link href="{% static "visit/lib/font-awesome/css/font-awesome.min.css"%}" rel="stylesheet">
<link href="{% static "visit/lib/owlcarousel/owl.carousel.min.css" %}" rel="stylesheet">
<link href="{% static "visit/lib/owlcarousel/owl.theme.min.css"%}" rel="stylesheet">
<link href="{% static "visit/lib/owlcarousel/owl.transitions.min.css" %}" rel="stylesheet">
<!-- Main Stylesheet File -->
<link href="{%static "visit/css/style.css"%}" rel="stylesheet">
<!--Your custom colour override - predefined colours are: colour-blue.css, colour-green.css, colour-lavander.css, orange is default-->
<link href="#" id="colour-blue" rel="stylesheet">
</head>
<body class="page-index has-hero">
<!--Change the background class to alter background image, options are: benches, boots, buildings, city, metro -->
<div id="background-wrapper" class="city" data-stellar-background-ratio="0.1">
<!-- ======== #Region: #navigation ======== -->
<div id="navigation" class="wrapper">
<!--Hidden Header Region-->
<div class="header-hidden collapse">
<div class="header-hidden-inner container">
<div class="row">
<div class="col-md-3">
<h3>
About Us
</h3>
<p>Ekyam is dedicated to support and nourish Startups and accelaration</p>
<i class="fa fa-plus"></i> Learn more
</div>
<div class="col-md-3">
<!--#todo: replace with company contact details-->
<h3>
Contact Us
</h3>
<address>
<strong>EKYAM</strong>
<abbr title="Address"><i class="fa fa-pushpin"></i></abbr>
MMMDU, Mullana, Ambala- Haryana
<br>
<abbr title="Phone"><i class="fa fa-phone"></i></abbr>
8219984448
<br>
<abbr title="Email"><i class="fa fa-envelope-alt"></i></abbr>
info#ekyam.com
</address>
</div>
<div class="col-md-6">
<!--Colour & Background Switch for demo - #todo: remove in production-->
<h3>
Theme Variations
</h3>
<div class="switcher">
<div class="cols">
Backgrounds:
<br>
Benches Boots Buildings
City Metro
</div>
<div class="cols">
Colours:
<br>
Orange Green Blue <a href="#lavender" class="colour lavender "
title="Lavender">Lavender</a>
</div>
</div>
<p>
<small>Selection is not persistent.</small>
</p>
</div>
</div>
</div>
</div>
<!--Header & navbar-branding region-->
<div class="header">
<div class="header-inner container">
<div class="row">
<div class="col-md-8">
<!--navbar-branding/logo - hidden image tag & site name so things like Facebook to pick up, actual logo set via CSS for flexibility -->
<a class="navbar-brand" title="Home" href = "{% url "visit:index"%}">
<h1 class="hidden">
<h1>EKYAM</h1>
</h1>
</a>
<br/>
<div class="navbar-slogan">
Hub Of StartUp
<br> By The Brogrammers
</div>
</div>
<!--header rightside-->
<div class="col-md-4">
<!--user menu-->
<ul class="list-inline user-menu pull-right">
</ul>
<ul class="list-inline user-menu pull-right">
<li class="user-register"><i class="fa fa-edit text-primary "></i> Register</li>
<li class="user-login"><i class="fa fa-sign-in text-primary"></i> Login</li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div class="navbar navbar-default">
<!--mobile collapse menu button-->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<!--everything within this div is collapsed on mobile-->
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav" id="main-menu">
<li class="icon-link">
<i class="fa fa-home"></i>
</li>
<li class="dropdown">
Comunity<b class="caret"></b>
<!-- Dropdown Menu -->
<ul class="dropdown-menu">
<li class="dropdown-header"> </li>
<li>Services</li>
<li>About Us</li>
<li>Login</li>
<li>Sign-Up</li>
<li class="dropdown-footer">Connect</li>
</ul>
</li>
<li>Join Us</li>
<li class="dropdown dropdown-mm">
Mega Menu<b class="caret"></b>
<!-- Dropdown Menu -->
<ul class="dropdown-menu dropdown-menu-mm dropdown-menu-persist">
<li class="row">
<ul class="col-md-6">
<li class="dropdown-header">Websites and Apps</li>
<li>Analysis and Planning</li>
<li>User Experience / Information Architecture</li>
<li>User Interface Design / UI Design</li>
<li>Code & Development / Implementation & Support</li>
</ul>
<ul class="col-md-6">
<li class="dropdown-header">Enterprise solutions</li>
<li>Business Analysis</li>
<li>Custom UX Consulting</li>
<li>Quality Assurance</li>
</ul>
</li>
<li class="dropdown-footer">
<div class="row">
<div class="col-md-7">Like the lite version? <strong>Get the extended version of Flexor.</strong></div>
<div class="col-md-5">
<i class="fa fa-cloud-download"></i> Get It Now
</div>
</div>
</li>
</ul>
</li>
</ul>
</div>
<!--/.navbar-collapse -->
</div>
</div>
</div>
<div class="hero" id="highlighted">
<div class="inner">
<!--Slideshow-->
<div id="highlighted-slider" class="container">
<div class="item-slider" data-toggle="owlcarousel" data-owlcarousel-settings='{"singleItem":true, "navigation":true, "transitionStyle":"fadeUp"}'>
<!--Slideshow content-->
<!--Slide 1-->
{%block content%}
{%endblock%}
</div>
<div class="col-md-6 hidden-xs">
<img src="img/slides/slide2.png" alt="Slide 2" class="center-block img-responsive">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer id="footer" class="block block-bg-grey-dark" data-block-bg-img="img/bg_footer-map.png" data-stellar-background-ratio="0.4">
<div class="container">
<div class="row" id="contact">
<div class="col-md-3">
<address>
<strong>JunityMe Inc</strong>
<br>
<i class="fa fa-map-pin fa-fw text-primary"></i> Maharishi Markendeshver Engineering College
<br>
<i class="fa fa-phone fa-fw text-primary"></i> 8219984448
<br>
<i class="fa fa-envelope-o fa-fw text-primary"></i> info#junity.com
<br>
</address>
</div>
Top
</div>
</footer>
The problem is, only this template is getting rendered. When I click on the other options on the navigation bar, the url changer(/incubator/) but the template remains the same.
urls.py:
from django.conf.urls import url
from . import views
app_name = 'main'
urlpatterns = [
url(r'^', views.home, name='home'),
url(r'incubators/', views.incubators, name='incubators'),
url(r'about/', views.about, name='about'),
]
I don't see any kinds of error. Somehow I think my urls are unable to connect to views.py.
views.py:
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return render(request, 'main/home.html')
def incubators(request):
return render(request, 'main/incubators.html')
def about(request):
return HttpResponse("dsfsddsf")
Please suggest edits if I can make it as simple as possible.
The problem is
url(r'^', views.home, name='home'),
The ^ sign means start of url so that matches all urls that have a start, i.e every url. So any URL will be rendered by views.home.
move that one to the bottom of the list, Then it will only match anything when all the other URLs have tried and it will do what you want.
If you really want to match only / then add
url(r'^$', views.home, name='home'),
$ means the end of an url, so that matches where there is nothing at all between the start and the end, i.e a empty url path