Django url pattern issue in python 2.7.6 - python

I searched a lot about my problem but couldn't find a solution probably because I am not good at looking or understanding. But I am searching about this for 2 days but couldn't find something that solves it.
I am working on a project with django.When I run the website I get no error. but when I click the buttons (home page and contact stuff), http://127.0.0.1:8000/first/first/first/first/iletisim.html it makes something like this. everytime I click iletisim button (its in turkish contact in english) it adds /first itself and nothing changes on the webpage it stays still on the homepage.
Edited : another issue is I also can't log in as admin. İf go in to /admin it redirects me to home page...
Here is an example
I only made contact blog and homepage until this point. I will try to put folder orders in here so mybe you guys will have an idea about the later.
haliyikama/haliyikama/settings.py
INSTALLED_APPS = [
'first',
'blog',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
haliyikama/haliyikama/urls.py
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^', include('first.urls')),
url(r'^blog/', include('blog.urls')),
]
haliyikama/first/urls.py
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^', views.index, name = 'index'),
url(r'^home', views.index, name = 'home'),
url(r'^first/iletisim', views.contact, name = 'iletisim')
]
haliyikama/first/views.py
from django.shortcuts import render
def index(request):
return render(request, 'first/home.html')
def contact(request):
return render(request,'first/iletisim.html', {'content':['Eger bizimle iletisime gecmek isterseniz mail adresimizi kullanabilirsiniz.', 'gulumhali#outlook.com']})
When I try to put $ sign in the my-site urls.py file at first place it does not open anypage it gaves 404 error indicates that I shouldn't put $ but if I don't put that I am stuck in home page.
These are the html files if you guys need to solve my problem;
These are in haliyikama/first/templates/first
iletisim.html
{% extends "first/header.html" %}
{% block content %}
{% for c in content %}
<p>{{c}}</p>
{%endfor%}
{% endblock %}
home.html
{% extends "first/header.html" %}
{% block content %}
<div class = "hero-unit">
<div class="container">
<h2 class="text-center">Gülüm Halı Yıkama Servisi</h2>
<p class="text-center">Kaliteli hizmetin adresi</p>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div id="Gülüm-Halı-Yıkama-Servisi" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#Gülüm-Halı-Yıkama-Servisi" data-interval="1000" data-slide-to="0" class="active"></li>
<li data-target="#Gülüm-Halı-Yıkama-Servisi" data-interval="1000" data-slide-to="1"></li>
<li data-target="#Gülüm-Halı-Yıkama-Servisi" data-interval="1000" data-slide-to="2"></li>
<li data-target="#Gülüm-Halı-Yıkama-Servisi" data-interval="1000" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="/static/images/1.jpg" alt="1" class = "img-responsive">
<div class="carousel-caption">
<h3 class="bg-primary">Halılarınız bizimle güvende.</h3>
<p>Profesyonel bir şekilde halılarınızın bakımı ve güvenliği Gülüm Halı Yıkama Servisi güvencesiyle gerçekten mümkün! Bu fırsattan yararlanabilmek için hemen size yakın bayiliğimizi arayabilirsiniz.</p>
</div>
</div>
<div class="item">
<img src="/static/images/2.jpg" alt="2" class = "img-responsive">
<div class="carousel-caption">
<h3 class="bg-primary">Hem ucuz, Hem kaliteli!</h3>
<p>Kalite ararken cüzdanınız boşalması, ucuzluk ararken halılarınızın yıpranması derdiniz bitti! Kaliteyi ve ucuzluğu sizler için birleştirdik. </p>
</div>
</div>
<div class="item">
<img src="/static/images/3.jpg" alt="3" class = "img-responsive">
<div class="carousel-caption">
<h3 class="bg-primary">Yüzleri güldüren komfor.</h3>
<p>Verdiğimiz kaliteli hizmetin en önemli amacı, müşteri memnuniyetidir.</p>
</div>
</div>
<div class="item">
<img src="/static/images/4.jpg" alt="4" class = "img-responsive">
<div class="carousel-caption">
<h3 class="bg-primary">Tam Zamanında!</h3>
<p>Teslimat süresi müşteri ile anlaşılan zamanda gerçekleştirilmesi garantisiyle...</p>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#Gülüm-Halı-Yıkama-Servisi" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Önceki</span>
</a>
<a class="right carousel-control" href="#Gülüm-Halı-Yıkama-Servisi" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Sonraki</span>
</a>
</div>
</div>
</div>
</div>
<div class = "container">
<div class = "row">
<div class = "col-xs-6 col-sm-3">
<h4>Hizmet verdiğimiz alanlar</h4>
<p>Şuanda Başakşehir ve Esenyurt olmak üzere iki bayiliğimiz bulunmakta. Bu bayilikler aracılığıyla çok geniş bir çevreye hizmetlerimizi sunuyoruz. Kendi bölgenizin de bu bayilikler kapsamında olup olmadığını görmek için Bölgeleri Göster butonuna tıklayınız.</p>
<a class = "btn btn-primary btn-lg" data-target = "#DENEME" role = "button" data-toggle = "modal">Bölgeleri Göster</a>
</div>
<div class = "col-xs-6 col-sm-3">
<h4>Hizmet verdiğimiz alanlar</h4>
<p>Şuanda Başakşehir ve Esenyurt olmak üzere iki bayiliğimiz bulunmakta. Bu bayilikler aracılığıyla çok geniş bir çevreye hizmetlerimizi sunuyoruz. Kendi bölgenizin de bu bayilikler kapsamında olup olmadığını görmek için Bölgeleri Göster butonuna tıklayınız.</p>
<a class = "btn btn-primary btn-lg" data-target = "#DENEME1" role = "button" data-toggle = "modal">Example</a>
</div>
<div class = "col-xs-6 col-sm-3">
<h4>Hizmet verdiğimiz alanlar</h4>
<p>Şuanda Başakşehir ve Esenyurt olmak üzere iki bayiliğimiz bulunmakta. Bu bayilikler aracılığıyla çok geniş bir çevreye hizmetlerimizi sunuyoruz. Kendi bölgenizin de bu bayilikler kapsamında olup olmadığını görmek için Bölgeleri Göster butonuna tıklayınız.</p>
<a class = "btn btn-primary btn-lg" data-target = "#DENEME2" role = "button" data-toggle = "modal">Example</a>
</div>
<div class = "col-xs-6 col-sm-3">
<h4>Hizmet verdiğimiz alanlar</h4>
<p>Şuanda Başakşehir ve Esenyurt olmak üzere iki bayiliğimiz bulunmakta. Bu bayilikler aracılığıyla çok geniş bir çevreye hizmetlerimizi sunuyoruz. Kendi bölgenizin de bu bayilikler kapsamında olup olmadığını görmek için Bölgeleri Göster butonuna tıklayınız.</p>
<a class = "btn btn-primary btn-lg" data-target = "#DENEME3" role = "button" data-toggle = "modal">Example</a>
</div>
</div>
</div>
</div>
{% endblock %}
header.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gülüm Halıyıkama</title>
<meta charset="utf-8" />
<meta name="description" content="Halı Yıkama Servisi">
<meta name="keywords" content="ucuz halıyıkama,başakşehir,halıyıkama,esenyurt,kaliteli halıyıkama">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% load staticfiles %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body class="body" style="background-color:#f6f6f6">
<div class = "navbar navbar-default navbar-fixed-top">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" 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>
<a class="navbar-brand" href="home"> <img alt="Brand" src= "/static/images/logo.jpg"</a><a class="navbar-brand" href="home">Gülüm Halı®</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active">Anasayfa <span class="sr-only">(current)</span></li>
<li>Bayiler</li>
<li>Vizyonumuz</li>
<li>Misyonumuz</li>
<li class="dropdown">
</li>
<ul class="nav navbar-nav navbar-right">
<li>İletişim</li>
<li class="dropdown">
Daha Fazla<span class="caret"></span>
<ul class="dropdown-menu">
<li>Anasayfa</li>
<li>Bayiler</li>
<li>Vizyonumuz</li>
<li role="separator" class="divider"></li>
<li>Misyonumuz</li>
</ul>
</li>
</ul>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
<div>
{% block content %}
{% endblock %}
</div>
<div class = "navbar navbar-inverse navbar-fixed-bottom">
<div class = "navbar-inner">
<div class = "container footer-margin-top">
<p class="muted pull-right" ><ins>Haydar Öztürk tarafından Bootsrap ile oluşturuldu.</ins></p>
<p class="muted pull-left" >Bütün hakları saklıdır. 2016</p>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="DENEME" tabindex="-1" role="dialog" aria-labelledby="modal0">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title" id="modal0">Bayilere göre bölgeler</h2>
</div>
<div class="modal-body">
<h3>Başahşehir</h3>
<p> Başakşehir şubemiz, Başakşehir,Kayaşehir,Altınşehir,Şahintepe,Tahtakale,Bahçeşehir ve Esenkent'in bütün mahallelerini,cadde ve sokaklarını kapsamaktadır. </p>
<h3>Esenyurt</h3>
<p> Esenyurt şubemiz, Beylikdüzü,Esenyurt ve Avcılar ilçelerinin bütün mahalle,cadde ve sokaklarını kapsamaktadır. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="DENEME1" tabindex="-1" role="dialog" aria-labelledby="modal1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title" id="modal1">Bayilere göre bölgeler</h2>
</div>
<div class="modal-body">
<h3>Başahşehir</h3>
<p> Başakşehir şubemiz, Başakşehir,Kayaşehir,Altınşehir,Şahintepe,Tahtakale,Bahçeşehir ve Esenkent'in bütün mahallelerini,cadde ve sokaklarını kapsamaktadır. </p>
<h3>Esenyurt</h3>
<p> Esenyurt şubemiz, Beylikdüzü,Esenyurt ve Avcılar ilçelerinin bütün mahalle,cadde ve sokaklarını kapsamaktadır. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="DENEME2" tabindex="-1" role="dialog" aria-labelledby="modal2">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title" id="modal2">Bayilere göre bölgeler</h2>
</div>
<div class="modal-body">
<h3>Başahşehir</h3>
<p> Başakşehir şubemiz, Başakşehir,Kayaşehir,Altınşehir,Şahintepe,Tahtakale,Bahçeşehir ve Esenkent'in bütün mahallelerini,cadde ve sokaklarını kapsamaktadır. </p>
<h3>Esenyurt</h3>
<p> Esenyurt şubemiz, Beylikdüzü,Esenyurt ve Avcılar ilçelerinin bütün mahalle,cadde ve sokaklarını kapsamaktadır. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="DENEME3" tabindex="-1" role="dialog" aria-labelledby="modal3">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title" id="modal3">Bayilere göre bölgeler</h2>
</div>
<div class="modal-body">
<h3>Başahşehir</h3>
<p> Başakşehir şubemiz, Başakşehir,Kayaşehir,Altınşehir,Şahintepe,Tahtakale,Bahçeşehir ve Esenkent'in bütün mahallelerini,cadde ve sokaklarını kapsamaktadır. </p>
<h3>Esenyurt</h3>
<p> Esenyurt şubemiz, Beylikdüzü,Esenyurt ve Avcılar ilçelerinin bütün mahalle,cadde ve sokaklarını kapsamaktadır. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="/static/js/bootstrap.js"></script>
</body>
</html>
I thought <a href="{% url name_of_register_url %}>Register</a> This solution could solve my problem but it didn't. mybe partly did. after I implant this solution to my header.html file it become like this;
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gülüm Halıyıkama</title>
<meta charset="utf-8" />
<meta name="description" content="Halı Yıkama Servisi">
<meta name="keywords" content="ucuz halıyıkama,başakşehir,halıyıkama,esenyurt,kaliteli halıyıkama">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% load staticfiles %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body class="body" style="background-color:#f6f6f6">
<div class = "navbar navbar-default navbar-fixed-top">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" 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>
<a class="navbar-brand" href="{% url home.html %}"> <img alt="Brand" src= "/static/images/logo.jpg"</a><a class="navbar-brand" href="{% url home.html %}">Gülüm Halı®</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active">Anasayfa <span class="sr-only">(current)</span></li>
<li>Bayiler</li>
<li>Vizyonumuz</li>
<li>Misyonumuz</li>
<li class="dropdown">
</li>
<ul class="nav navbar-nav navbar-right">
<li>İletişim</li>
<li class="dropdown">
Daha Fazla<span class="caret"></span>
<ul class="dropdown-menu">
<li>Anasayfa</li>
<li>Bayiler</li>
<li>Vizyonumuz</li>
<li role="separator" class="divider"></li>
<li>Misyonumuz</li>
</ul>
</li>
</ul>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
<div>
{% block content %}
{% endblock %}
</div>
<div class = "navbar navbar-inverse navbar-fixed-bottom">
<div class = "navbar-inner">
<div class = "container footer-margin-top">
<p class="muted pull-right" ><ins>Haydar Öztürk tarafından Bootsrap ile oluşturuldu.</ins></p>
<p class="muted pull-left" >Bütün hakları saklıdır. 2016</p>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="DENEME" tabindex="-1" role="dialog" aria-labelledby="modal0">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title" id="modal0">Bayilere göre bölgeler</h2>
</div>
<div class="modal-body">
<h3>Başahşehir</h3>
<p> Başakşehir şubemiz, Başakşehir,Kayaşehir,Altınşehir,Şahintepe,Tahtakale,Bahçeşehir ve Esenkent'in bütün mahallelerini,cadde ve sokaklarını kapsamaktadır. </p>
<h3>Esenyurt</h3>
<p> Esenyurt şubemiz, Beylikdüzü,Esenyurt ve Avcılar ilçelerinin bütün mahalle,cadde ve sokaklarını kapsamaktadır. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="DENEME1" tabindex="-1" role="dialog" aria-labelledby="modal1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title" id="modal1">Bayilere göre bölgeler</h2>
</div>
<div class="modal-body">
<h3>Başahşehir</h3>
<p> Başakşehir şubemiz, Başakşehir,Kayaşehir,Altınşehir,Şahintepe,Tahtakale,Bahçeşehir ve Esenkent'in bütün mahallelerini,cadde ve sokaklarını kapsamaktadır. </p>
<h3>Esenyurt</h3>
<p> Esenyurt şubemiz, Beylikdüzü,Esenyurt ve Avcılar ilçelerinin bütün mahalle,cadde ve sokaklarını kapsamaktadır. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="DENEME2" tabindex="-1" role="dialog" aria-labelledby="modal2">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title" id="modal2">Bayilere göre bölgeler</h2>
</div>
<div class="modal-body">
<h3>Başahşehir</h3>
<p> Başakşehir şubemiz, Başakşehir,Kayaşehir,Altınşehir,Şahintepe,Tahtakale,Bahçeşehir ve Esenkent'in bütün mahallelerini,cadde ve sokaklarını kapsamaktadır. </p>
<h3>Esenyurt</h3>
<p> Esenyurt şubemiz, Beylikdüzü,Esenyurt ve Avcılar ilçelerinin bütün mahalle,cadde ve sokaklarını kapsamaktadır. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="DENEME3" tabindex="-1" role="dialog" aria-labelledby="modal3">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title" id="modal3">Bayilere göre bölgeler</h2>
</div>
<div class="modal-body">
<h3>Başahşehir</h3>
<p> Başakşehir şubemiz, Başakşehir,Kayaşehir,Altınşehir,Şahintepe,Tahtakale,Bahçeşehir ve Esenkent'in bütün mahallelerini,cadde ve sokaklarını kapsamaktadır. </p>
<h3>Esenyurt</h3>
<p> Esenyurt şubemiz, Beylikdüzü,Esenyurt ve Avcılar ilçelerinin bütün mahalle,cadde ve sokaklarını kapsamaktadır. </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="/static/js/bootstrap.js"></script>
</body>
</html>
After this change it gave this error.
error looks like this
This is the text in this picture;
NoReverseMatch at /
Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.9
Exception Type: NoReverseMatch
Exception Value:
Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location: /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in _reverse_with_prefix, line 508
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/haydar/haliyikama',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Server time: Sat, 7 May 2016 11:15:09 +0000
And this is the line it gives error says debug tool
/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in _reverse_with_prefix
lookup_view_s = "%s.%s" % (m, n)
else:
lookup_view_s = lookup_view
patterns = [pattern for (possibility, pattern, defaults) in possibilities]
raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
"arguments '%s' not found. %d pattern(s) tried: %s" %
(lookup_view_s, args, kwargs, len(patterns), patterns)) ...
class LocaleRegexURLResolver(RegexURLResolver):
"""
A URL resolver that always matches the active language code as URL prefix.

There are a few issues with your setup; but nothing that's major:
Your file is called haliyikama/first/url.py; but you are including it as url(r'^', include('first.urls')), (note the urls); you need to change the name of your file to haliyikama/first/urls.py.
Your patterns are also incorrect. Your pattern needs to be ^$ for the very first pattern in your url list.
The reason admin is not working, is because you haven't mapped it to any url pattern; try adding url(r'^admin/', admin.site.urls), to your main urls.py.
href="{% url home.html %}" this is not how you use the url tag, you need to pass it the name of the view, not the template; like this href="{% url 'home' %}".
I also suggest you read a quick primer on regular expressions because these are important when defining urls; as they work on the concept of pattern matching.
Here are some quick tips:
Lets say you have a pattern like this url(r'^home/')
This means any url that starts with home/, so it will match home/foo/bar/zoo/hello along with anything else home/hello.html etc. This is why usually when you have an "open ended" pattern like this, you usually include a lot of other urls after it, like this url(r'^home/', include('home.urls')).
Now, when you do url(r'^home/', include('home.urls')) this means "any url that starts with home/, match it against the list of urls found in home/urls.py file".
Lets say in our home/urls.py file, we have:
url(r'^$', views.index),
This ^$ means a blank string, so views.index will be called when the url is http://localhost:8080/home/
Here is another example:
url(r'^members/$', views.members),`
Now this will match home/members/.
Hopefully this helps clarify the issues you are facing. Please have a read through the tutorial which covers these concepts.

The main problem I had was using the URL tags. If you had some problem like this and pop-up in here, here is the answer how I solve my problem with the help I get from Burhan Khalid;
Yes my url tag was wrong but instead of href="{% url home %}" doing something like that I should have do something like href="{% url 'home' %}"
there is not much difference but it will help to call the name so it can send you that link. The Url tags in the HTML file was wrong.

Related

why Index error at / list index out of range?

hello im having a problem with the index code in my views.py, aparrently the HTML index is out of range for some reason i dont understand, because before i wanted to make the page to add images as avatars work perfectly fine
the index .html is in a templates folder , inside the APP folder, and i created a media folder outside of the APP for storage of media
this is the views.py
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
from django.contrib.auth.views import LoginView, LogoutView
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from .forms import PosteoForm, SignUpForm, UserEditForm
from .models import Posteo, Avatar
from django.urls import reverse_lazy
# Create your views here.
def mostrar_index(request):
imagenes = Avatar.objects.filter(user=request.user.id)
return render(request, 'index.html', {'url': imagenes[0].images.url})
def mostrar_gallery(request):
return render(request,'gallery.html')
def mostrar_contact(request):
return render(request,'contact.html')
def cursoPost(request):
return render(request,'Posts.html')
#login_required
def crear_post(request):
if request.method == 'POST':
posteo = PosteoForm(request.POST)
print('posteo')
if posteo.is_valid():
data = posteo.cleaned_data
posteo = Posteo (titulo=data['titulo'], texto=data['texto'])
posteo.save()
return render(request,'index.html')
else:
posteo = PosteoForm()
print('formulario')
return render(request,'Posts.html',{'posteo':posteo})
def buscar_post(request):
return render(request,'buscador.html')
def buscador (request):
if request.GET.get ('titulo', False):
titulo = request.GET ['titulo']
post = Posteo.objects.filter(titulo__icontains=titulo)
return render (request, 'buscador.html',{'post':post})
else:
respuesta = 'no hay datos'
return render (request, 'buscador.html', {'respuesta':respuesta})
class PosteoList(ListView):
model = Posteo
template_name = 'mostrar_post.html'
class PosteoDetail(DetailView):
model = Posteo
template_name = 'posteo_detalle.html'
def base(request):
return render(request,'base.html')
class PosteoDeleteView(LoginRequiredMixin, DeleteView):
model = Posteo
template_name = 'post_confirm_delete.html'
success_url = '/mostrarPost'
class PosteoUpdateView(LoginRequiredMixin, UpdateView):
model = Posteo
template_name = 'modificar_post.html'
success_url = '/mostrarPost'
fields =['titulo', 'subtitulo','texto','nombre', 'email']
class SignUpView(CreateView):
form_class = SignUpForm
success_url = reverse_lazy('index')
template_name = "registro.html"
def editar_usuario(request):
usuario = request.User
if request.method == 'POST':
usuario_form = UserEditForm(request.POST)
if usuario_form.is_valid():
informacion = usuario_form.cleaned_data
usuario.username = informacion['username']
usuario.email = informacion['email']
usuario.password1 = informacion['password1']
usuario.password2 = informacion ['password2']
usuario.save()
return render(request,'inicio.html')
else:
usuario_form = UserEditForm(initial={'username': usuario.username, 'email': usuario.email})
return render(request, 'admin_update.html', {'form': usuario_form, 'usuario': usuario})
class AdminLoginView(LoginView):
template_name = 'login.html'
class AdminLogoutView(LogoutView):
template_name = 'logout.html'
the index.html
<!DOCTYPE html>
<html lang="en">
<head>
{% load static %}
<!-- basic -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- mobile metas -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<!-- site metas -->
<title>Entro</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="author" content="">
<!-- fevicon -->
<!-- bootstrap css -->
<link rel="stylesheet" href={% static "css/bootstrap.min.css" %}>
<!-- style css -->
<link rel="stylesheet" href={% static "css/style.css" %}>
<!-- Responsive-->
<link rel="stylesheet" href={% static "css/responsive.css" %}>
<!-- Scrollbar Custom CSS -->
<link rel="stylesheet" href={% static "css/jquery.mCustomScrollbar.min.css" %}>
<!-- Tweaks for older IEs-->
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" media="screen">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
</head>
<!-- body -->
<body class="main-layout">
<!-- loader -->
<div class="loader_bg">
<div class="loader"><img src={% static "images/loading.gif" %} alt="#" /></div>
</div>
<!-- end loader -->
<!-- header -->
<header>
<!-- header inner -->
<div class="header-top">
<div class="header">
<div class="container">
<div class="row">
<div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col logo_section">
<div class="full">
<div class="center-desk">
<!-- <div class="logo">
<img src={% static "images/logo.png" %} alt="#" />
</div> --> <!-- boton izquierdo de ticket -->
</div>
</div>
</div>
<div class="col-xl-10 col-lg-10 col-md-10 col-sm-9">
<div class="menu-area">
<div class="limit-box">
<nav class="main-menu ">
<ul class="menu-area-main">
<li class="active"> Inicio </li>
<li> Mostrar Posts </li>
<li> Crear Posts </li>
<li> Buscar Posts </li>
<li> Galeria </li>
<li> base </li>
<li> Usuario </li>
<li> <a class="last_manu" href="{% url 'buscar' %}"><img src={% static "images/search_icon.png" %} alt="#" /></a> </li>
{% if request.user.is_authenticated %}
<li> Logout </li>
{% else %}
<li> Login </li>
{% endif %}
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- end header inner -->
<!-- end header -->
<section class="slider_section">
<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 active">
<div class="container">
<div class="carousel-caption">
<div class="row">
<div class="col-md-12">
<div class="text-bg">
{% if request.user.is_authenticated %}
<img src="{{url}}" alt="">
<h1>Hola {{user.username}} como te va? </h1>
<p>Si deseas deslogearte haz click aqui! </p>
<li> Logout </li>
{% else %}
<span>La web</span>
<h1>de musica para vos</h1>
<p>Esta es una web diseñada para dejar al alcance de tus manos lo que necesitas para tu musica</p>
<li> Login </li>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="container ">
<div class="carousel-caption">
<div class="row">
<div class="col-md-12">
<div class="text-bg">
<span>La web</span>
<h1>de musica para vos</h1>
<p>Haz click en los botones para crear algun posteo o ver los posteos existentes</p>
Crea un post Post Musicales
</div>
</div>
</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="container">
<div class="carousel-caption ">
<div class="row">
<div class="col-md-12">
<div class="text-bg">
<span>La web</span>
<h1>de musica para vos</h1>
<p>y algo más..</p>
Crea un post Post Musicales
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
<i class="fa fa-long-arrow-left" aria-hidden="true"></i>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
<i class="fa fa-long-arrow-right" aria-hidden="true"></i>
</a>
</div>
</section>
</div>
</header>
<!-- about -->
<div id="about" class="about">
<div class="container">
<div class="row display_boxflex">
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12">
<div class="about-box">
<h2>Acerca de Nosotros</h2>
<p>Somos dos estudiantes del curso de Python de Coder House y este es el blog de presentacion de proyecto final</p>
Leer más
</div>
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12">
<div class="about-box">
<figure><img src={% static "images/about.png" %} alt="#" /></figure>
</div>
</div>
</div>
</div>
</div>
<!-- end abouts -->
<!-- upcoming -->
<!-- end upcoming -->
{% block codigoDinamico %}
{% endblock %}
<!-- Gallery -->
<!--
<div id="gallery" class="Gallery">
<div class="container">
<div class="row display_boxflex">
<div class="col-xl-8 col-lg-8 col-md-8 col-sm-12">
<div class="row">
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 margi_bott">
<div class="Gallery_img">
<figure><img src={% static "images/Gallery1.jpg"%} alt="#"/></figure>
</div>
<div class="hover_box">
<ul class="icon_hu">
<h3>Music night</h3>
<li><img src={% static "icon/h.png"%} alt="#"/></li>
<li><img src={% static "icon/h.png"%} alt="#"/></li>
</ul>
</div>
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 margi_bott">
<div class="Gallery_img">
<figure><img src={% static "images/Gallery2.jpg"%} alt="#"/></figure>
</div>
<div class="hover_box">
<ul class="icon_hu">
<h3>Music night</h3>
<li><img src={% static "icon/h.png"%} alt="#"/></li>
<li><img src={% static "icon/h.png"%} alt="#"/></li>
</ul>
</div>
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 margi_bott1">
<div class="Gallery_img">
<figure><img src={% static "images/Gallery3.jpg"%} alt="#"/></figure>
</div>
<div class="hover_box">
<ul class="icon_hu">
<h3>Music night</h3>
<li><img src={% static "icon/h.png"%} alt="#"/></li>
<li><img src={% static "icon/h.png"%} alt="#"/></li>
</ul>
</div>
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12">
<div class="Gallery_img">
<figure><img src={% static "images/Gallery4.jpg"%} alt="#"/></figure>
</div>
<div class="hover_box">
<ul class="icon_hu">
<h3>Music night</h3>
<li><img src={% static "icon/h.png"%} alt="#"/></li>
<li><img src={% static "icon/h.png"%} alt="#"/></li>
</ul>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12">
<div class="Gallery_text">
<div class="titlepage">
<h2>Gallery</h2>
</div>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to usin</p>
Read More
</div>
</div>
</div>
</div>
</div>
-->
<!-- end Gallery -->
<!-- footer -->
<footr>
<div class="footer ">
<div class="container">
<div class="row">
<div class="col-md-12">
<form class="contact_bg">
<div class="row">
<div class="col-md-12">
<div class="titlepage">
<h2>Contactanos</h2>
</div>
<div class="col-md-12">
<input class="contactus" placeholder="Tu nombre" type="text" name="Your Name">
</div>
<div class="col-md-12">
<input class="contactus" placeholder="Tu Email" type="text" name="Your Email">
</div>
<div class="col-md-12">
<input class="contactus" placeholder="Numero de telefono" type="text" name="Your Phone">
</div>
<div class="col-md-12">
<textarea class="textarea" placeholder="Mensaje" type="text" name="Message"></textarea>
</div>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12">
<button class="send">Enviar</button>
</div>
</div>
</div>
</form>
</div>
<div class="col-md-12 border_top">
<form class="news">
<h3>Newsletter</h3>
<input class="newslatter" placeholder="ENTER YOUR MAIL" type="text" name=" ENTER YOUR MAIL">
<button class="submit">Subscribe</button>
</form>
</div>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 ">
<div class="row">
<!-- <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 ">
<div class="address">
<ul class="loca">
<li>
<img src={% static "icon/loc.png" %}alt="#" />Locations
<li>
<img src={% static "icon/call.png"%} alt="#" />+12586954775 </li>
<li>
<img src={% static "icon/email.png"%} alt="#" />demo#gmail.com </li>
</ul>
-->
</div>
</div>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 ">
<ul class="social_link">
<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-linkedin-square" aria-hidden="true"></i></li>
<li><i class="fa fa-instagram" aria-hidden="true"></i></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="copyright">
<p>Copyright 2019 All Right Reserved By Free html Templates</p>
</div>
</div>
</div>
</footr>
<!-- end footer -->
<!-- Javascript files-->
<script src={% static "js/jquery.min.js"%}></script>
<script src={% static "js/popper.min.js"%}></script>
<script src={% static "js/bootstrap.bundle.min.js"%}></script>
<script src={% static "js/jquery-3.0.0.min.js"%}></script>
<script src={% static "js/plugin.js"%}></script>
<!-- sidebar -->
<script src={% static "js/jquery.mCustomScrollbar.concat.min.js"%}></script>
<script src={% static "js/custom.js"%}></script>
<script src="https:cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.js"></script>
</body>
</html>
def mostrar_index(request):
imagenes = Avatar.objects.filter(user=request.user.id)
return render(request, 'index.html', {'avatar': imagenes})
{% if request.user.is_authenticated %}
{% if avatar %}
<img src="{{avatar.images.url}}" alt="">
{% else %}
<img src="{% static 'default/image.ext' %}" alt="">
{% endif %}
<h1>Hola {{user.username}} como te va? </h1>
<p>Si deseas deslogearte haz click aqui! </p>
<li> Logout </li>
{% else %}
...
{% endif %}

How to view images from folder in flask web app?

I had this issue when I first started on most of the pictures, only one showed on my web page so I uploaded the pictures to a google drive and used each url. It worked but the pictures loaded slowly so I went to try the pictures in a folder thing again and they all show with the alt tag and a broken image icon.
{% extends "base.html" %} {% block title %}Home{% endblock %}
{% block content%}
<main role="main">
<div id="myCarousel" class="carousel slide" data-ride="carousel" style="margin-top:25px;">
<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 active">
<div class="svg-wrapper background-image" style="background-image: url('../images/smiling_five_blue_uniform.jpg'); -webkit-background-composite: border; background-size: cover;">
<!-- <img src="../images/smiling_five_blue_uniform.jpg" class="d-block w-100" alt="KG2 children smiling in school uniform outside TH."> -->
<!-- <img src="https://www.drive.google.com/uc?id=1r-pe153xqSnx08uRzVByAIgXuDmYcLHV" class="d-block w-100" alt="KG2 children smiling in school uniform outside TH."> -->
<svg class="bd-placeholder-img" style="background-image: url('../images/smiling_five_blue_uniform.jpg')" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img"><rect width="100%" height="100%" fill="#777"/>
</svg>
</div>
<div class="container">
<div class="carousel-caption text-left">
<h1>Welcome to Towering Heights Group of Schools</h1>
<p>This is the official website for the Towering Heights group of Schools in Akure, Ondo State.</p>
<p><a class="btn btn-lg btn-primary" href="/about" role="button">See what we're about</a></p>
</div>
</div>
</div>
<div class="carousel-item">
<img src="../images/green_dress_girl.JPG" class="d-block w-100" alt="Children engageing with each other in non-uniform."/>
<!-- <img src="https://www.drive.google.com/uc?id=1tUXIMfDEUmmo5O4yX2ITmJ0-h87XKzW6" class="d-block w-100" alt="Children engageing with each other in non-uniform."> -->
<svg class="bd-placeholder-img" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img"><rect width="100%" height="100%" fill="#777"/></svg>
<div class="container">
<div class="carousel-caption">
<h1>Another home for your kids</h1>
<p>We have a warm, safe, secure environment where children have the opportunity
to develop a love of learning and independence.</p>
<p><a class="btn btn-lg btn-primary" href="/contact" role="button">Get in touch today!</a></p>
</div>
</div>
</div>
<div class="carousel-item">
<img src="../images/kids_roundtable.jpg" class="d-block w-100" alt="Children playing at a classroom table inside TH."/>
<!-- <img src="https://www.drive.google.com/uc?id=1NRC2t0FnsJo2gTz_PSmZkA92l-szX2cL" class="d-block w-100" alt="Children playing at a classroom table inside TH."> -->
<svg class="bd-placeholder-img" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img"><rect width="100%" height="100%" fill="#777"/></svg>
<div class="container">
<div class="carousel-caption text-right">
<h1>Admissions are currently ongoing.</h1>
<p>Ensure your child gets the best possible education.</p>
<p><a class="btn btn-lg btn-primary" href="/contact" role="button">Get in touch today</a></p>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</main>
<!-- Marketing messaging and featurettes
================================================== -->
<!-- Wrap the rest of the page in another container to center all the content. -->
<div class="container marketing" style="width:800px; margin:0 auto;">
<!-- Three columns of text below the carousel -->
<div class="container-fluid" style="margin-top:50px;">
<!-- Example row of columns -->
<div class="row" >
<div class="col-lg-4">
<h2>Admissions</h2>
<p>Choosing the right school marks a new beginning in the life of your child.<br>
Contact us as early as possible to have your child assessed and ready for school. </p>
<p><a class="btn btn-secondary" href="/contact" role="button">View details »</a></p>
</div><!-- /.col-lg-4 -->
<div class="col-lg-4">
<h2>Calendar</h2>
<p>Terms, exams, holidays, keep up to date on what's hapenning when so you don't fall behind. </p>
<p><a class="btn btn-secondary" href="/calendar" role="button">View details »</a></p>
</div><!-- /.col-lg-4 -->
<div class="col-lg-4">
<h2>Latest News</h2>
<p>Check out what's been happening at THS</p>
<p><a class="btn btn-secondary" href="/news" role="button">View details »</a></p>
</div><!-- /.col-lg-4 -->
</div><!-- /.row -->
<hr>
</div> <!-- /container -->
{% endblock %}

Django Template extract list

I have a list:
productlinks = [google.com, tes.com, lol.com]
prices = [$134, $123,$123]
I wanna extract those list to my django template inside the bootsrap. Here is my django template code:
<section class="py-5">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
{% for link in productlinks %}
<div class="col mb-5">
<div class="card h-100">
<!-- Product image-->
<img class="card-img-top" src="https://dummyimage.com/450x300/dee2e6/6c757d.jpg" alt="..." />
<!-- Product details-->
<div class="card-body p-4">
<div class="text-center">
<!-- Product name-->
<h5 class="fw-bolder">Fancy Product</h5>
<!-- Product price--> x
$40.00 - $80.00 -> price must be here using loop to extract the list
</div>
</div>
<!-- Product actions-->
<div class="card-footer p-4 pt-0 border-top-0 bg-transparent">
<div class="text-center"><a class="btn btn-outline-dark mt-auto" href="{{ link }}" target="_blank">View options</a></div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
So basically, I wanna also extract the prices list but i dont know how to place the loop after the my productlinks loop. Because it will ruins the result.
and here is my views code:
return render(request, '/home.html', {
'productlinks': productlinks,
'prices': productprices
}
)
views
return render(request, '/home.html', {
'data': zip(productlinks,productprices)
}
)
template
<section class="py-5">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
{% for link,price in data %}
<div class="col mb-5">
<div class="card h-100">
<!-- Product image-->
<img class="card-img-top" src="https://dummyimage.com/450x300/dee2e6/6c757d.jpg" alt="..." />
<!-- Product details-->
<div class="card-body p-4">
<div class="text-center">
<!-- Product name-->
<h5 class="fw-bolder">Fancy Product</h5>
<!-- Product price--> x
{{ price }}
</div>
</div>
<!-- Product actions-->
<div class="card-footer p-4 pt-0 border-top-0 bg-transparent">
<div class="text-center"><a class="btn btn-outline-dark mt-auto" href="{{ link }}" target="_blank">View options</a></div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</section>

Not able to insert data in second table in same DB in Django

I am using one db with 2 tables. Using template inheritance & I am able to insert data in one table from one template but not able to insert another data in another table from second template. While able to insert in db 'userdetails' but not able to insert data in 'logindb'. (Not sharing template from which able to insert data). If required will share.
Help with be highly appreciated.
**models.py**
from django.db import models
class user_details(models.Model):
name = models.CharField(max_length=20)
email = models.EmailField()
mobile = models.CharField(max_length=20)
category = models.CharField(max_length=10)
member = models.BooleanField(default=False)
query = models.CharField(max_length=500)
class Meta:
managed = True
db_table = 'userdetails'
class signups(models.Model):
sname = models.CharField(max_length=20)
semail = models.EmailField()
spassword = models.CharField(max_length=20)
scpassword = models.CharField(max_length=20)
class Meta:
managed = True
db_table = 'logindb'
**views.py**
from django.http import HttpResponse
from django.shortcuts import render
from .models import user_details, signups
def index(request):
context = {"home_page": "active"} # used to make template active when clicked on it
return render(request, 'index.html', context)
def about(request):
context = {"about_page": "active"}
return render(request, 'about.html', context)
def contact(request):
context = {"contact_page": "active"}
if request.method == "POST":
name = request.POST.get('name', '')
email = request.POST.get('email', '')
mobile = request.POST.get('mobile', '')
category = request.POST.get('category', '')
member = True if request.POST.get('member') else False
query = request.POST.get('query', '')
contact = user_details(name=name, email=email, mobile=mobile, category=category, member=member, query=query)
contact.save()
return render(request, 'contact.html', context)
def signup(request):
if request.method == "POST":
sname = request.POST.get('sname', '')
semail = request.POST.get('semail', '')
spassword = request.POST.get('spassword', '')
scpassword = request.POST.get('scpassword', '')
signup = signups(sname=sname, semail=semail, spassword=spassword, scpassword=scpassword)
signup.save()
return render(request, 'index.html')
**basic.html**
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<title>VP Blog!</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="/" style="color:orange">VP Blog</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item {{ home_page }} ">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item {{ about_page }}">
<a class="nav-link" href="/about">About</a>
</li>
<!--<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Views
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>-->
<li class="nav-item {{ contact_page }}">
<a class="nav-link" href="/contact">Contact Us</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-light my-2 my-sm-0" type="submit">Search</button>
</form>
<button type="button" class="btn btn-danger mx-2" data-toggle="modal" data-target="#loginModal">Login</button>
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#signupModal">Sign Up</button>
</div>
</nav>
<!-- Login Modal -->
<div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Login Page</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1">
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Remember me</label>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Login</button>
</div>
</div>
</div>
</div>
<!-- Sign Up Modal -->
<div class="modal fade" id="signupModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel1">Sign Up Page</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="" method="post">{% csrf_token %}
<div class="form-group">
<label for="sname">Name</label>
<input type="text" class="form-control" id="sname" name='sname' aria-describedby="emailHelp">
</div>
<div class="form-group">
<label for="sname">Email address</label>
<input type="email" class="form-control" id="semail" name='semail' aria-describedby="emailHelp">
<small id="emailHelp1" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="sname">Password</label>
<input type="password" class="form-control" id="spassword" name='password'>
</div>
<div class="form-group">
<label for="sname">Confirm Password</label>
<input type="password" class="form-control" id="scpassword" name='scpassword'>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success">Register</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% block body %} {% endblock %}
<footer class="container my-4">
<p class="float-right">Back to top</p>
<p>© 2020-2021 Vivek Pvt. Ltd., Inc. · Privacy · Terms</p>
</footer>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</body>
</html>
Sorted out. I was missing function name in action in template.

Dynamically load content in Bootstrap Modal with AJAX with Django

I am a begineer in Django framework I want to Dynamically load content in Bootstrap Modal with AJAX
something like this
https://makitweb.com/demo/modal_ajax/index.php
(to be clear its not my code result i want to do dometing like this)
I found many tutorials on internet but i want some guidance on the part where button is pressed and modal shows data related to that item.
Please pardon me if it's a bad question
here is code
models.py
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=200)
img = models.ImageField(upload_to='prodpics', default=None)
price = models.FloatField(max_length=30)
category = models.CharField(max_length=30)
description = models.CharField(max_length=200)
def __str__(self):
return self.name
views.py
from django.shortcuts import render
from .models import Product
# Create your views here.
def products(request):
prods = Product.objects.all()
return render(request, 'products.html',{'prods':prods})
prod.html
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<!-- <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors"> -->
<!-- <meta name="generator" content="Jekyll v4.0.1"> -->
<title>Products</title>
<link rel="canonical" href="https://getbootstrap.com/docs/4.5/examples/starter-template/">
<!-- Bootstrap core CSS -->
<link href="{% static 'css/bootstrap.css' %}" rel="stylesheet">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
<!-- Custom styles for this template -->
<link href="{% static 'css/starter-template.css' %}" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-md bg-light navbar-light fixed-top">
<!-- <a class="navbar-brand" href="#">Navbar</a> -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Explore Us</a>
</li>
<!-- <li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li> -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Sign In/Sign Up</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Sign In</a>
<a class="dropdown-item" href="#">Sign Up</a>
</div>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-primary my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<main role="main" class="container">
<div class="starter-template">
<h1>Products</h1>
<div class="album py-5 bg-light">
<div class="container">
<div class="row">
{% for prod in prods %}
<div class="col-md-4">
<div class="card mb-4 shadow-sm">
<img class="card-image-top" src="{{prod.img}}" alt="">
<div class="card-body">
<h2 class="card-text text-center">{{prod.name}}</h2>
<p class="card-text text-center">${{prod.price}}</p>
<div class="d-flex justify-content-between align-items-center">
<!-- <div class="btn-group center"> -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Know More</button><br>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{{prod.name}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{prod.description}}
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-primary">Request demo</button>
<!-- </div> -->
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</main><!-- /.container -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="../assets/js/vendor/jquery.slim.min.js"><\/script>')</script><script src="{% static 'js/vendor/bootstrap.bundle.js' %}"></script></body>
</html>
Still this question is related to bootstrap not Django. You should match id's of both button and modal template.
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#prod.id">Know More</button><br>
<!-- Modal -->
<div class="modal fade" id="{{prod.id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{{prod.name}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{prod.description}}
</div>
</div>
</div>
</div>

Categories

Resources