I am PasswordChangeForm form to change password. I am trying to display an error message when given password is either less than 8 or greater than 64 (in below code "form.data['new_password1']"). So when I enter password with less than 8 characters, then I am seeing error message "New password should have minimum 8 characters and maximum 64 characters" hit. But error message not displayed on UI page. This is because "return render(request, 'registration/change_password.html'" renders again.
Could you please help me how can we display error message on PasswordChangeForm.
#login_required(login_url='/login/')
def change_password_view(request):
global passwordValidationFailed
passwordValidationFailed = False
if (request.method == 'POST'):
form = PasswordChangeForm(request.user, request.POST)
if len(form.data['new_password1']) >= 8 and len(form.data['new_password1']) <= 64:
if form.is_valid():
form.save()
messages.success(request, 'Your password was successfully updated!')
profile = request.user.get_profile()
profile.force_password_change = False
profile.save()
return render(request, 'dau_gui_app/status_view.html', {'title': "System Status"})
else:
passwordValidationFailed = False
messages.error(request, 'Please correct the error below.')
else:
raise form.ValidationError("New password should have minimum 8 characters and maximum 64 characters")
else:
form = PasswordChangeForm(request.user)
return render(request, 'registration/change_password.html', {
'form': form
})
Here is my change_password.html
{% load i18n %}
{% load admin_static %}{% load firstof from future %}<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="static/dau_gui_app/fontawesome-free-5.3.1-web/css/all.min.css">
<link rel='shortcut icon' type='image/x-icon' href='/static/dau_gui_app/images/favicon.ico' />
<link rel="stylesheet" href="/static/dau_gui_app/style.css">
<link rel="stylesheet" href="/static/dau_gui_app/bootstrap.min.css">
<link rel="stylesheet" href="/static/dau_gui_app/w3.css">
<link rel="stylesheet" href="/static/dau_gui_app/dataTables/datatables.css">
<script type="text/javascript" src="/static/dau_gui_app/dataTables/jQuery-3.3.1/jquery-3.3.1.js"></script>
<script type="text/javascript" src="/static/dau_gui_app/dataTables/datatables.js"></script>
<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static 'admin/css/base.css' %}{% endblock %}" />
{% block extrastyle %}{% endblock %}
<title>
{% block title %}Change Password{% endblock %}
</title>
</head>
{% load i18n %}
<body id="login_page">
<DIV style="margin-left:auto;margin-right:auto;padding-top:100px;display:block;width:30%">
<DIV id="login_box">
<table id="logon_box_table" >
<!-- Title Bar -->
<TR >
<TD colspan='2' >
<DIV id='login_box_title'>
Update Password
</DIV>
</TD>
</TR>
<!-- Password -->
<TR >
<TD >
<div id= "logon-container" >
<img src="/static/dau_gui_app/images/logo.png" alt="">
<div id="alstom-logo-container"> <img src="/static/dau_gui_app/images/alstom_logo.png" alt="" style="width: 90px; height: 18px;"> </div>
<div id="version-container" >Software Version: 4.0</div>
</div>
</TD>
<TD style="width: 490px; height: 18px;">
{% block content %}
<form method="post">
{% csrf_token %}
{{ form }}
</TD>
</TR>
<TR >
<TR >
<TD colspan='2' style="text-align:center;padding:10px">
<button type="submit">Update Password</button>
</form>
{% endblock %}
</TD>
</TR>
</TABLE>
</DIV>
</DIV>
</body>
</html>
You are taking the wrong approach. You should validate the input in the Form, not in the View. That's because any error you raise in the form's full_clean() process will be caught and added to the form errors, which you display in your template.
In your view, when you do raise ValidationError(...), this actually produces an exception to be raised and hence, you return an HTTP 500 error.
Since you only need to clean one particular field, override the specific field's clean method inside the form as explained here:
def clean_new_password1(self):
data = self.cleaned_data['new_password1']
if len(data) < 8 or len(data) > 64:
raise form.ValidationError("New password should have minimum 8 characters and maximum 64 characters")
return data
Related
I am trying to use django-views-breadcrumbs to add breadcrumbs to a site. I can get it to work with some views but I am getting an error with a particular listview. When I attempt to visit this listview page I see the error.
The error appears to be related to a need for the correct context. So far I have not been able to figure this out.
The error:
NoReverseMatch at /projects/project/1/notes/
Reverse for 'projectnotes_list' with no arguments not found. 1 pattern(s) tried: ['projects/project/(?P<pk>[0-9]+)/notes/\\Z']
Request Method: GET
Request URL: http://co1.localhost:8000/projects/project/1/notes/
Django Version: 3.1.14
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'projectnotes_list' with no arguments not found. 1 pattern(s) tried: ['projects/project/(?P<pk>[0-9]+)/notes/\\Z']
Exception Location: /Users/user/.local/share/virtualenvs/osite-wGphEfbP/lib/python3.9/site-packages/django/urls/resolvers.py, line 689, in _reverse_with_prefix
Python Executable: /Users/user/.local/share/virtualenvs/osite-wGphEfbP/bin/python
Python Version: 3.9.6
Python Path:
['/Users/user/Desktop/otools',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
'/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
'/Users/user/.local/share/virtualenvs/osite-wGphEfbP/lib/python3.9/site-packages']
Server time: Sun, 20 Feb 2022 15:52:17 +0000
The list view:
class ProjectNotesList(ListBreadcrumbMixin,ListView):
model = ProjectNotes
template_name = 'company_accounts/project_notes.html'
comments = ProjectNotes.comments
def related_project(self, **kwargs):
project = get_object_or_404(Project, id=self.kwargs.get('pk'))
notes = ProjectNotes.objects.all
return notes
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
context['project'] = get_object_or_404(Project, id=self.kwargs.get('pk'))
return context
commentscount = ProjectNotes.objects.annotate(num_comments=Count('comments'))
The urls.py
from django.urls import path, include
from .views import CompanyProjects, CompanyProjectsDetailView, TodoCreateView, ProjectNotesList, ProjectNotesCreateView, ProjectCreateView, ProjectNotesDetailView, CompanyCompletedProjects, CompanyPausedProjects, TodosList, ProjectTodosDetailView, ProjectDocumentsList, ProjectDocumentsCreateView, ProjectDocumentsDetailView
from . import views
app_name = 'company_project'
urlpatterns = [
path('', CompanyProjects.as_view(), name='project_list'),
path('completed_projects', CompanyCompletedProjects.as_view(), name='completed_projects'),
path('paused_projects', CompanyPausedProjects.as_view(), name='paused_projects'),
path('add_project/', ProjectCreateView.as_view(), name='add_project'),
path('project/<int:pk>/', CompanyProjectsDetailView.as_view(), name='project_detail'),
path('project/<int:pk>/todos/', TodosList.as_view(), name='project_todos'),
path('project/<int:project_pk>/todo/<int:pk>/', ProjectTodosDetailView.as_view(), name='project_todo_detail'),
path('project/<int:pk>/add_todo/', TodoCreateView.as_view(), name='add_todo'),
path('project/<int:pk>/add_project_note/', ProjectNotesCreateView.as_view(), name='add_project_note'),
path('project/<int:pk>/notes/', ProjectNotesList.as_view(), name='projectnotes_list'),
#path('note/<int:pk>/add_project_note_comment/', ProjectNotesCommentCreateView.as_view(),
# name='add_project_note_comment'),
path('project/<int:project_pk>/note/<int:pk>/', ProjectNotesDetailView.as_view(), name='project_note_detail'),
path('project/<int:pk>/documents/', ProjectDocumentsList.as_view(), name='project_documents'),
path('project/<int:pk>/add_project_document/', ProjectDocumentsCreateView.as_view(), name='add_project_document'),
path('project/<int:project_pk>/document/<int:pk>/', ProjectDocumentsDetailView.as_view(), name='project_document_detail'),
]
The base and page templates:
base
<!DOCTYPE html>
{% load static %}
{% load view_breadcrumbs %}
<html>
<head>
<meta charset="utf-8">
<title>{% block title %}Site{% endblock title %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link type="text/x-scss" href="{% static 'bootstrap/scss/bootstrap.scss' %}" rel="stylesheet" media="screen">
<!-- Custom CSS -->
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}"/>
<link rel="shortcut icon" type="image/png" href="{% static 'core_images/OH_favicon.png' %}"/>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-VJRXH7YFXZ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-VJRXH7YFXZ');
</script>
</head>
<body>
<wrapper class="d-flex flex-column">
{% include 'nav.html' %}
<main class="flex-fill">
<div class="row">
<div class="col-12">
<br />
{% block breadcrumbs %}
{% render_breadcrumbs 'view_breadcrumbs/bootstrap4.html' %}
{% endblock breadcrumbs %}
{% block messages %}{% endblock messages %}
</div>
</div>
{% block content %}
<h1>Hello</h1>
{% endblock content %}
</main>
{% include 'footer.html' %}
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</wrapper>
</body>
</html>
page
<!-- templates/company_accounts/project_notes.html -->
{% extends 'base.html' %}
{% block content %}
<div class="section-container container">
<div class="general-section-header">
<div class="header-add-new">
<a class="btn btn-success" href="{% url 'company_project:add_project_note' project.pk %}" role="button">Add Note</a>
</div>
<h1>Notes for {{ project }}</h1>
</div>
{% if project.notes.all %}
{% for note in project.notes.all %}
<div class ="projectnotes-entry">
<div class="col-sm-8">
<div class="row-sm-6">
<div class="card mb-2">
<div class="card-body">
<div class="card-title">{{ note.title }}</div>
<div class="card-text">{{ note.body | safe | truncatewords:"20"|linebreaks }}
<div>{{ note.comments.all.count }} comments</div>
read more</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p>No notes have been have been added yet.</p>
{% endif %}
</div>
{% endblock content %}
There is a demo included with the breadcrumb app the provides some insight. However I have not been able to figure out how to add necessaryt context using code from the demo.
The demo code:
class TestListsView(ListBreadcrumbMixin, ListView):
model = TestModel
template_name = "demo/test-list.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
view_paths = []
for instance in self.object_list:
view_paths.append(
(
instance.name,
detail_instance_view_url(instance),
),
)
context["view_paths"] = view_paths
return context
validation error is not shown before also when i created form using form api i send error but is does not appear in html and now also when created User using UserCreationForm now also error not appered in html submitting this form without fillig single field.
views.py file
from django.shortcuts import render
from .forms import signup
# Create your views here.
def sign_up(request):
fm = signup()
if request.method == 'POST':
fm = signup(request.POST)
if fm.is_valid() :
print('until this runs')
fm.save()
else:
fm = signup()
print(fm.errors)
return render(request, 'at/signup.html', {'form': fm})
forms.py file
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class signup(UserCreationForm):
class Meta:
model=User
fields=['username','first_name','last_name','email']
html file
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<title>Form</title>
</head>
<body>
<div class="container" >
{{ form.non_field_errors }}
<form method="post" novalidate>
{% csrf_token %}
{{ fms.as_p }}
<button class="text-center btn btn-primary" type="submit">SUB</button>
</form>
</div>
</body>
</html>
tried this html code also but no erros are seen
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>user regisration</title>
</head>
<body>
{{ form.non_field_errors }}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{{ form.non_field_errors }}
<form action="" method='POST' novalidate>
{% csrf_token %}
{% for fm in form %}
{{fm.label_tag}} {{fm}} {{fm.errors|striptags}} <br> <br>
{% endfor %}
<input type="submit" value='submit'>
</form>
</body>
</html>
When rendering fields manually, you are responsible for displaying the error messages.
https://docs.djangoproject.com/en/3.1/topics/forms/#rendering-form-error-messages
I have a Django form where the person needs to add their details to subscribe and I want the page to show successful submission message below the submit button for few seconds (lets say 3) and then it should disappear and the form fields should be displayed empty.
The function definition in views.py is as follows :
def new_customer(request):
if request.method == "POST":
form = customer_form(request.POST)
if form.is_valid():
form.save()
messages.add_message(request, message_constants.SUCCESS, '✔️ SUCCESSFUL SUBSCRIPTION')
return HttpResponseRedirect('http://127.0.0.1:8000/subscribe/')
else:
form = customer_form()
return render(request,"new_customer.html",{'form':form})
The Django template :
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Subscribe</title>
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
<link href="{% static "nav.css" %}" rel="stylesheet">
<link href="{% static "form.css" %}" rel="stylesheet">
</head>
{% include "navbar.html" %}
<body>
<form method="POST" class="post-form" enctype="multipart/form-data">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn">Subscribe</button>
{% if messages %}
<ul id ="successMessage" class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %} style="color:green; font-size: 20px; list-style-type: none;">{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
</form>
</body>
</html>
The current code helps display the message for successful submission, as well as empty form fields but does not make it disappear.
Could anyone help ?
I suggest you use jQuery to make messages disappear and make form empty,
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script text="javascript">
setTimeout(fade_out, 3000);
function fade_out() {
$(".messages").fadeOut().empty();
}
$(".post-form")[0].reset(); // this is to reset the form
</script>
I am trying to use Templateview in Django to render a page with options for both adding to the database and retrieving some info from the database and displaying it. I am basing it on the tutorial at https://www.youtube.com/watch?v=VxOsCKMStuw
views.py:
class TestView(TemplateView):
template_name = 'app/sensor_name_tmpl.html'
def get(self, request):
form = SensorForm()
posts = Sensor.objects.all()
args = {'form': form, 'posts': posts}
return render(request, self.template_name, args)
def post(self, request):
form = SensorForm(request.POST)
if form.is_valid():
form.save()
text = form.cleaned_data['post']
form = SensorForm()
return redirect('sensor_name_tmpl:sensor_name_tmpl')
args = {'form': form, 'text': text}
return render(request, self.template_name, args)
urls.py:
urlpatterns = [
path('', views.index, name='index'),
url(r'^form1/$', views.get_sensor_name, name='GiveSensorName1'),
#url(r'^form2/$', TestView.as_view(), name='sensor_name_tmpl.html'),
path('form2/', TestView.as_view(), name='app/sensor_name_tmpl.html'),
url(r'^nested_admin/', include('nested_admin.urls')),
]
HTML template:
<!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">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$('#toggle').click(function() {
$('form').toggle('slow');
});
</script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<title>Hello world!</title>
</head>
<body>
<h3 class="text-success">Add Sensor</h3>
<br>
<!-- <form style="display:none;" method="post">-->
<form method="post">
{% csrf_token %}
<div class="row align-items-center">
<div class="col-sm-8">
<table>
{{ form1.as_table}}
</table>
<div class="mx-sm-2">
<input type="submit" value="Submit">
</div>
<br>
<br>
<h3 class = "text-success">Add Sensor View</h3>
<table>
{{ form2.as_table}}
</table>
<div class="mx-sm-2">
<input type="submit" value="Submit">
</div>
<br>
<br>
<h3 class="text-success">View Sensors</h3>
<table class="table">
<thead>
<tr>
<th scope="col">Sensor ID</th>
<th scope="col">Sensor Name</th>
</tr>
</thead>
<tbody>
{%for obj in obj%}
<tr>
<td>{{obj.sensor_id}}</td>
<td>{{obj.sensor_name}}</td>
<!-- <th scope="row">1</th>-->
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div>
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
</body>
</html>
The page renders the template but doesn't populate it with either the formfields or the data from the database.
The problem was with the HTML template where form1 and form2 have now been replaced with form and "obj" in the for loop has been replaced with "posts". The template now looks as follows:
<!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">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$('#toggle').click(function() {
$('form').toggle('slow');
});
</script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<title>Hello world!</title>
</head>
<body>
<h3 class="text-success">Add Sensor</h3>
<br>
<!-- <form style="display:none;" method="post">-->
<form method="post">
{% csrf_token %}
<div class="row align-items-center">
<div class="col-sm-8">
<table>
{{ form.as_table}}
</table>
<div class="mx-sm-2">
<input type="submit" value="Submit">
</div>
<br>
<br>
<h3 class = "text-success">Add Sensor View</h3>
<table>
{{ form.as_table}}
</table>
<div class="mx-sm-2">
<input type="submit" value="Submit">
</div>
<br>
<br>
<h3 class="text-success">View Sensors</h3>
<table class="table">
<thead>
<tr>
<th scope="col">Sensor ID</th>
<th scope="col">Sensor Name</th>
</tr>
</thead>
<tbody>
{%for obj in posts%}
<tr>
<td>{{obj.sensor_id}}</td>
<td>{{obj.sensor_name}}</td>
<!-- <th scope="row">1</th>-->
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div>
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
</body>
</html>
Being a beginner Django Developer, I will suggest that it is actually not advisable to use TemplateView class for any kind updating of objects or if your template is having a form. You can read more about this here.
I have a following problem. In login.html I added {% If user.is_authenticated %} and there everything work. I also added this in navbar.html and home.html, but there it doesn't work, and I don't know why.
This is my views.py
def index(request):
return render(request, 'website/home.html', {'user': user_panel})
def register(request):
registered = False
if request.method =='POST':
user_form = UserForm(data=request.POST)
profile_form = UserProfileForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'picture' in request.FILES:
profile.picture = request.FILES['picture']
profile.save()
registered = True
else:
print (user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileForm()
return render(request, 'website/register.html', {
'user_form': user_form,
'profile_form': profile_form,
'registered': registered})
def auth_login(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user:
if user.is_active:
login(request, user)
return HttpResponseRedirect(reverse('index'))
else:
return HttpResponse("Konto jest nieaktywne")
else:
print ("Invalid login details: {0}, {1}".format(username, password))
return HttpResponse("Invalid login details supplied.")
else:
return render(request, 'website/login.html', {})
basic.html
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" type = "text/css"/>
<link rel="stylesheet" href="{% static 'css/style.css' %}" type = "text/css"/>
<link href='https://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
</head>
<body>
{% include 'website/navbar.html' %}
{% block body_block %}
{% endblock %}
</body>
</html>
home.html
{% extends 'website/basic.html' %}
{% block body_block %}
{% load staticfiles %}
<div class="container-full-bg" style="background-image:url('{% static 'images/website/jumbotron-website.PNG' %}');" height="100%">
<div class="jumbotron" style="background: transparent">
<div class="container" style="margin-top: 6em"><h1>Agencja Reklamy FUX</h1>
<p>Nasza Agencja to firma z ponad dwudziestoletnią tradycją. Zajmujemy się głównie wielkoformatową
reklamą zewnętrzną, dającą niemalże nieograniczone możliwości przekazu.</p></div>
{% if user.is_authenticated %}
Hello {{ user.username }}
{% else %}
You are not loggin in
{% endif %}
</div>
</div>
{% endblock %}
navbar.html
{% load staticfiles %}
<nav class="navbar navbar-inverse navbar-fixed-top" style="background-color: #363636;">
<div class="container-fluid">
<div class = "container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" style="padding: 0em"><img src="{% static 'images/website/logo.png' %}"></img></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">Home <span class="sr-only">(current)</span></li>
<li>O Firmie</li>
<li>Oferta</li>
<li>Klienci</li>
<li>Praca</li>
<li>Kontakt</li>
{% if user.is_authenticated %}
<li>Wyloguj się</li>
{% else %}
<li>Zaloguj się</li>
{% endif %}
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</div>
</nav>
login.html
{% extends 'website/basic.html' %}
{% block body_block %}
<div class="container" style="margin-top: 8rem">
{% if not user.is_authenticated %}
<form id="login_form" method="post" action="/login/">
{% csrf_token %}
<div class="form-group" style="padding-right: 80rem">
<label for="username">Username</label>
<input type="text" class="form-control" name="username" size="60" />
</div>
<div class="form-group" style="padding-right: 80rem">
<label for="username">Password</label>
<input type="password" class="form-control" name="password" size="60" />
</div>
<div class="form-group" style="padding-right: 80rem">
<button type="submit" class="btn btn-default" value="submit">Submit</button>
</div>
</form>
{% else %}
You are logged! {{ user.username }}
{% endif %}
</div>
{% endblock %}