I run into a problem without understanding where it could come from.
I have the same website in Django 3.0.8 under environment which works on one side on a PC with windows 10:
On the other side, on an old PC with Xubuntu 20.04:
Everything is the same: code, files, environments, version of python (3.8). However, the Xubuntu version doesn't perform well as you can see.
Do you have any idea what could be blocking? I have the impression that Bootstrap and FontAwesomeIcon are not working correctly.
.
EDIT : This is the code of the page.html
{% load i18n %}
{% load static %}
{% load bootstrap5 %}
{% get_current_language as language_code %}
<!DOCTYPE html>
<html lang="{{ language_code }}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Une vie électrique sans barrière.">
<meta name="author" content="Pierre TREMELO">
<link rel="icon" href="{% static 'favicon.ico' %}">
<title>ElyanDeal</title>
<link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
<!-- CUSTOMING -->
<link href="{% static 'css/fontawesome.css' %}" rel="stylesheet">
</head>
<body>
<img src="{% static 'accounts/fond_accueil.jpg' %}" class="superbg" />
<nav class="navbar navbar-expand-md navbar-dark bg-dark static-top">
<a class="navbar-brand" href="/">
<i class="fas fa-home"></i> {% trans 'Home' %}
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
{% if request.user.is_authenticated %}
<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">
{% trans 'Mon compte' %}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{% url 'accounts:change_profile' %}?next={{ request.path }}">
{% trans 'Profil' %}
</a>
<a class="dropdown-item" href="{% url 'accounts:change_password' %}">
{% trans 'Mot de passe' %}
</a>
<a class="dropdown-item" href="{% url 'accounts:change_email' %}">
{% trans 'Email' %}
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'accounts:log_out' %}">
{% trans 'Déconnexion' %}
</a>
</div>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'accounts:log_in' %}">{% trans 'Connexion' %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'accounts:sign_up' %}">{% trans 'Créer un compte' %}</a>
</li>
{% endif %}
</ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{% url 'change_language' %}">{{ language_code|upper }}</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid mt-3">
{% bootstrap_messages %}
{% block content %}
No content.
{% endblock %}
</div>
<script src="{% static 'vendor/jquery/jquery-3.4.1.min.js' %}"></script>
<script src="{% static 'vendor/popper/popper.min.js' %}"></script>
<script src="{% static 'vendor/bootstrap/js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/ie10-viewport-bug-workaround.js' %}"></script>
</body>
</html>
And this one for the content of the {% block content %} :
{% extends 'layouts/default/page.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap5 %}
{% block content %}
<div class="center-etroit" style="background-color:transparent; max-width:500px;">
<div class="card">
<div class="card-header">
<h4>{% trans 'Connexion' %}</h4>
</div>
<div class="card-body">
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
<button class="btn btn-primary">{% trans 'Connexion' %}</button>
</form>
<hr>
<ul>
<li>
{% trans 'Mot de passe oublié ?' %}
</li>
<li>
{% trans 'Identifiant oublié ?' %}
</li>
<li>
{% trans "Renvoyer le code d'activation" %}
</li>
</ul>
</div>
</div>
</div>
{% endblock %}
I ended up finding the issu! I had installed 'django-fontawesome-5' instead of 'fontawesome-free' in my virtual environment. Now that I have reinstalled the correct package, the appearance is fixed!
Related
I have created an application and everything seems to be working perfectly apart from this one page that I created. The contents are there, however, the styling of the page is not being applied. It actually seems as if the contents of the page I have created is overriding the layout styles.
The layout.html template has worked for every other webpage, and I am so confused it doesn't seem to work for this page.
To give context, this page involves filtering posts by company.
My HTML template is:
<!DOCTYPE html> {% extends "layout.html" %} {% block content %} {% for post in posts.items %}
<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="{{ url_for('company_posts', company=post.company) }}">{{ post.company }}</a>
<small class="text-muted">{{ post.date_posted }}</small>
</div>
<h2><a class="article-title" href="#">{{ post.job_title }}</a></h2>
<p class="article-content">{{ post.sector }}</p>
<p class="article-content">{{ post.location }}</p>
<p class="article-content">{{ post.employment_type }}</p>
More Info
</div>
</article>
{% endfor %} {% for page_num in posts.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %} {% if page_num %} {% if posts.page == page_num %}
<a class="btn btn-info mb-4" href="{{ url_for('jobs', page=page_num)}}">{{ page_num }}</a> {% else %}
<a class="btn btn-outline-info mb-4" href="{{ url_for('jobs', page=page_num)}}">{{ page_num }}</a> {% endif %} {% else %} ... {% endif %} {% endfor %} {% endblock content %}
My route is:
#app.route("/company/<string:company>")
def company_posts(company): #show all company job posts from specific company
page = request.args.get('page', 1, type=int)
posts = Job_Requirements.query.filter_by(company=company).order_by(Job_Requirements.id.desc()).paginate(per_page=4)
return render_template('company_posts.html', posts=posts)
This is my layout.html template
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"> {% if title %}
<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='main.css')}}">
<title>{{ title }} | CVLink</title>
{% else %}
<title>CVLink</title>
{% endif %}
</head>
<body>
<header class="site-header">
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
<div class="container">
<a class="navbar-brand mr-4" href="/">CVLink</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarToggle">
<div class="navbar-nav mr-auto">
<a class="nav-item nav-link" href="{{ url_for('home') }}">Home</a>
<a class="nav-item nav-link" href="{{ url_for('jobs') }}">Jobs</a>
</div>
<!-- Navbar Right Side -->
<div class="navbar-nav ms-auto">
{% if current_user.is_authenticated %}
<!--<a class="nav-item nav-link" href="{{ url_for('employer_account') }}">Employer Account</a>-->
<a class="nav-item nav-link" href="{{ url_for('employer_account') }}">Post A Job</a>
<a class="nav-item nav-link" href="{{ url_for('account') }}">Profile</a>
<a class="nav-item nav-link" href="{{ url_for('logout') }}">Logout</a> {% else %}
<a class="nav-item nav-link" href="{{ url_for('login') }}">Login</a>
<a class="nav-item nav-link" href="{{ url_for('register') }}">Register</a> {% endif %}
</div>
</div>
</div>
</nav>
</header>
<main role="main" class="container">
<div class="row">
<div class="col-md-8">
{% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for category, message in messages %}
<div class="alert alert-{{ category }}">
{{ message}}
</div>
{% endfor%} {% endif %} {% endwith %} {% block content %}{% endblock %}
</div>
<!--<div class="col-md-4">
<div class="content-section">
<h3>Noticeboard</h3>
<p class="text-muted">More Information</p>
<ul class="list-group">
<li class="list-group-item list-group-item-light">Latest Job Posts</li>
<li class="list-group-item list-group-item-light">Announcements</li>
<li class="list-group-item list-group-item-light">Calendars</li>
<li class="list-group-item list-group-item-light">etc</li>
</ul>
</div>
</div>-->
</div>
</main>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
Any help will be much appreciated.
Did you tried remove <!DOCTYPE html> from your template?
According to the documentation here should escape...
I followed the steps in guide in https://django-private-chat.readthedocs.io/en/latest/readme.html:
base.html:
{% block extra_js %}{% endblock extra_js %}
settings.py:
INSTALLED_APPS = (
...
'django_private_chat',
...
)
CHAT_WS_SERVER_HOST = 'localhost'
CHAT_WS_SERVER_PORT = 5002
CHAT_WS_SERVER_PROTOCOL = 'ws'
urlpatterns = [
"other urls"
url(r'^', include('django_private_chat.urls')),
]
After starting the server I go to http://127.0.0.1:8000/dialogs/some-of-the-users and there is no result whatsoever, the page is empty.
The console displaying:
Uncaught ReferenceError: $ is not defined
at username:128
django version= 3.0.6
python version= 3.7.6
and the latest version of django-private-messaging
It's my first time implementing a chat app so I hope I'm not missing anything fundamental. Have a nice day!
base.html:
<!DOCTYPE html>
{% load static %}
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<link rel="stylesheet" href="{% static 'css/dropdown.css' %}">
<link rel="stylesheet" href="{% static 'css/intro.css' %}">
<link rel="icon" type="image/ico" href="{% static 'icons\favicon.ico' %}"/>
<title>Document</title>
</head>
<body>
<div class="overlay2" id="overlay2">
<div id=fullscrean>
<img class=virus2 src="{% static 'icons\virus-new-color.png' %}" alt="virus">
<h4></h3>
<a href="/user/loginUser" class=mantar>login</a>
<a href="/user/register" class=mantar>register</a>
<button class=button-geri onclick="close('overlay2') ">geri</button>
</div>
</div>
<div class="overlay" id="overlay">
<div id=fullscrean>
<img class=virus2 src="{% static 'icons\virus-new-color.png' %}" alt="virus">
<h4></h3>
<a href="/user/loginUser" class=mantar>enter</a>
<a href="/user/register" class=mantar>register</a>
<button class=button-geri onclick="kapat('overlay') ">back</button>
</div>
</div>
<div class="overlay4" id="overlay4">
<div id=fullscrean>
<img class=virus2 src="{% static 'icons\virus-new-color.png' %}" alt="virus">
<h4></h3>
<a href="/user/loginUser" class=mantar></a>
<a href="/user/register" class=mantar></a>
<button class=button-geri onclick="kapat('overlay4') "></button>
</div>
</div>
<div class="overlay5" id="overlay5">
<div id=fullscrean>
<img class=virus2 src="{% static 'icons\virus-new-color.png' %}" alt="virus">
<h3></h3>
<a href="/user/loginUser" class=mantar></a>
<a href="/user/register" class=mantar></a>
<button class=button-geri onclick="kapat('overlay5') "></button>
</div>
</div>
<div class="overlay3" id="overlay3">
<div id=fullscrean2>
<img class=virus3 src="{% static 'icons\delete.png' %}"
alt="sil"></button>
<h4></h3>
<button class=button-cancel onclick="kapat('overlay3')">vazgeç</button>
<button class=button-doit id=doit>sil</button>
</div>
</div>
<div class="overlay6" id="overlay6">
<div id=fullscrean3>
<div class=scrollable-div id=scrollable-div>
{% for i in page_list %}
{% if i == entries2.number %}
<a class=scroll-select id=exception2 href="?page={{i}}"><span id=exception>{{i}}</span></a>
{% else %}
<a class=scroll-select href="?page={{i}}">{{i}}</a>
{% endif %}
{% endfor %}
</div>
{% if entries2.has_previous or entries.has_previous %}
<button class=button-prevp>önceki</button>
{% endif %}
{% if entries2.has_next or entries.has_next %}
<button class=button-nextp>sonraki</button>
{% endif %}
</div>
</div>
<div class="overlay7" id="overlay7">
<div id=fullscrean2>
<img class=virus3 src="{% static 'icons\delete.png' %}"
alt="sil"></button>
<h4>etiketin silinsin mi?</h3>
<button class=button-cancel onclick="kapat('overlay7')">vazgeç</button>
<button class=button-doit id=doit2>sil</button>
</div>
</div>
<div class=line></div>
<header>
<div class="header-top">
<div class=logo-holder>
<img class=virus src="{% static 'icons\virus-new-color.png' %}" alt="virus">
</div>
<div class=search-holder>
<input class=search type="text" placeholder="search it..." />
<button type="submit" class=search-button><img src="{% static 'icons\icons8_search.png' %}"
alt="search"></button>
</div>
</div>
<nav>
<div class=mobile-only>
<ul class=navul>
<li>
<b></b>
</li>
<li>
<b></b>
</li>
{% if request.user.is_authenticated %}
<li>
<b></b>
</li>
<li>
</li>
<li>
<b></b>
</li>
{% else %}
<li>
<b></b>
</li>
<li>
<b></b>
</li>
{% endif %}
</ul>
</div>
</nav>
</header>
<div class=line2></div>
<main id=main>
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li {% if message.tags %} class="{{ message.tags }}" {% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% block extra_js %}{% endblock extra_js %}
{% block body %}
{% endblock body %}
</main>
</body>
<script src="{% static 'js/jquery.mini.js' %}"></script>
<script src="{% static 'js/dropdown.js' %}"></script>
<script>
setTimeout(function(){
var message_ele = document.getElementsByClassName("messages")[0];
message_ele.style.visibility = 'hidden';
message_ele.style.opacity = 0;
message_ele.style.transition= "visibility 0s 2s, opacity 2s linear";
}, 2000);
setTimeout(function(){
var message_ele = document.getElementsByClassName("errorlist")[0];
message_ele.style.visibility = 'hidden';
message_ele.style.opacity = 0;
message_ele.style.transition= "visibility 0s 2s, opacity 2s linear";
}, 2000);
function kapat(id){
var geri=document.getElementById(id);
geri.style.display="none";
$('body').css('overflow', 'scroll');
}
$("#overlay6").click(function (e) {
if(e.target !== e.currentTarget) return;
$("#overlay6").css("display","none")
$('body').css('overflow', 'scroll');
});
$("#overlay3").click(function (e) {
if(e.target !== e.currentTarget) return;
$("#overlay3").css("display","none")
$('body').css('overflow', 'scroll');
});
$("#overlay7").click(function (e) {
if(e.target !== e.currentTarget) return;
$("#overlay7").css("display","none")
$('body').css('overflow', 'scroll');
});
</script>
{% block javascript %}{% endblock %}
</html>
I've came across an issue where message is displayed twice even though its called only once. Sometimes only one message is displayed however, most of the time 2 messages are.
My view:
def register(request):
if request.method == 'POST':
form = UserRegisterForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, f'Account created has been creted! You can log-in now.')
return redirect('login')
else:
if request.user.is_authenticated:
messages.error(request, 'You are loged-in and in order to registrate you must be loged-out.')
return redirect('blog-home')
else:
form = UserRegisterForm()
return render(request, 'users/register.html', {'form': form,'title':'Register Page'})
And here is my template:
Base.html
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{% static 'blog/main.css' %}">
{% if title %}
<title> Django blog - {{ title }}</title>
{% else %}
<title> Django blog</title>
{% endif %}
</head>
<body>
<header class="site-header">
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
<div class="container">
<a class="navbar-brand mr-4" href="{% url 'blog-home' %}">Django Blog</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarToggle">
<div class="navbar-nav mr-auto">
<a class="nav-item nav-link" href="{% url 'blog-home' %}">Home</a>
<a class="nav-item nav-link" href="{% url 'blog-about' %}">About</a>
</div>
<!-- Navbar Right Side -->
<div class="navbar-nav">
{% if user.is_authenticated %}
<a class="nav-item nav-link" href="{% url 'profile' %}">{{ user.username }}</a>
<a class="nav-item nav-link" href="{% url 'logout' %}">Logout</a>
{% else %}
<a class="nav-item nav-link" href="{% url 'login' %}">Login</a>
<a class="nav-item nav-link" href="{% url 'register' %}">Register</a>
{% endif %}
</div>
</div>
</div>
</nav>
</header>
<main role="main" class="container">
<div class="row">
<div class="col-md-8">
{% if messages %}
{% for message in messages %}
{% if message.tags == 'error' %}
<div class="alert alert-danger">
{{ message }}
</div>
{% else %}
<div class="alert alert-{{ message.tags }}">
{{ message }}
</div>
{% endif %}
{% endfor %}
{% endif %}
{% block content %}{% endblock %}
</div>
<div class="col-md-4">
<div class="content-section">
<h3>Our Sidebar</h3>
<p class='text-muted'>You can put any information here you'd like.
<ul class="list-group">
<li class="list-group-item list-group-item-light">Latest Posts</li>
<li class="list-group-item list-group-item-light">Announcements</li>
<li class="list-group-item list-group-item-light">Calendars</li>
<li class="list-group-item list-group-item-light">etc</li>
</ul>
</p>
</div>
</div>
</div>
</main>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
You can see that in the {% if messages %} block, message is called only once.
And here is the main html:
{% extends "blog/base.html" %}
{% block content%}
{% for post in posts %}
<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ post.author.first_name }}</a>
<small class="text-muted">{{ post.date_posted|date:"d F, Y"}}</small>
</div>
<h2><a class="article-title" href="#">{{ post.title }}</a></h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
{% endfor %}
{% endblock content%}
Any ideas what could be causing this?
this is how my base.html looks like,everything was working fine until i did some changes adding jquery
{% load static %}
<!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://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type ="text/css" href="{% static 'pmmvyapp/main.css' %}">
<link href="{% static 'js/jquery.js' %}" rel="stylesheet">
{% if title %}
<title> PMMVY-{{ title }}</title>
{% else %}
<title>PMMVY</title>
{% endif %}
</head>
<body>
<header class="site-header">
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
<div class="container">
<a class="navbar-brand mr-4"><img src="{% static 'images/left-logo.png' %}" width="83" height="89" class='d-inline-block' alt=""/>
<span style="color:white"> Ministry of Women & Child Development | GoI</span>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarToggle">
{% if user.is_authenticated %}
<a class="btn btn-primary mr-4" href="{% url 'aganwadi' %}">Aganwadi</a>
<a class="btn btn-primary mr-4" href="{% url 'applyonline' %}">Apply online</a>
{% else %}
<div class="navbar-nav mr-auto">
<a class="navbar-brand mr-4"><img src="{% static 'images/emblem-dark.png' %}" width="60" height="80" class='d-inline-block' alt=""/> <span style="color:white" >Pradhan Mantri Matru Vandana Yojana</span> </a>
</div>
{% endif %}
<!-- Navbar Right Side -->
<div class="navbar-nav">
{% if user.is_authenticated %}
<div class="navbar-nav mr-auto">
<a class="btn btn-primary mr-4" href="{% url 'admin:index' %}"> Admin site </a>
<a class="btn btn-primary mr-4" href="{% url 'logout' %}">Logout</a>
</div>
{% else %}
<div class="navbar-nav mr-auto">
<a class="navbar-brand mr-4" href="{% url 'login' %}"><img src="{% static 'images/pm.png' %}" width="65" height="70" class='d-inline-block' alt=""/> <span class="btn btn-primary" style="color:black mr-4" >Login</span> </a>
</div>
{% endif %}
</div>
</div>
</div>
</nav>
</header>
<!--mainsec-->
<main role="main" class="container">
<div>
{% if messages %}
{% for message in messages%}
<div class="alert alert-{{ message.tags }}">
{{ message }}
</div>
{% endfor %}
{% endif %}
</div>
<div class="row">
{% block content %}{% endblock %}
</div>
</main>
<!--end mainsec-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="{% static 'js/custom.js' %}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</body>
</html>
this is how my applyonline.html looks like
<body ng-app="">
{% extends "pmmvyapp/base.html" %}
{% load crispy_forms_tags %}
{% load static %}
{% block content%}
<div class="col-md-8">
<form method="post" action="/personal_detail/" enctype="multipart/form-data">
<div class="group">
<div class="hide" id="q1">
</div>
</div>
</div>
<div class="hide" id="q2">two</div>
<div class="hide" id="q3">three</div>
<div class="hide" id="q4">four</div>
</div>
<div style="margin-bottom:10px ">
<button id="next">Next</button> <button id="prev">Previous</button>
</div>
<button type="submit" class="btn btn-primary" style="margin-bottom:10px ">Submit</button>
</form>
</div>
<style>
.hide
{
display : none;
}
</style>
{% endblock %}
</body>
my settings.py
INSTALLED_APPS = [
'jquery',
'captcha',
'users.apps.UsersConfig',
'pmmvyapp.apps.PmmvyappConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
my models.py where I am returning either of the one names
class Personal_Detail(models.Model):
beneficiary_adhaar_name=models.TextField(blank=True, null=True)
adhaarno=models.IntegerField(blank=True, null=True)
adhaarcopy = models.FileField(upload_to='adhaar/')
idcard=models.TextField(blank=True, null=True)
adhaar_eid=models.IntegerField(blank=True,null=True)
beneficiary_id_name=models.TextField(blank=True, null=True)
idno=models.IntegerField(blank=True, null=True)
idcopy=models.FileField(upload_to='identitycard/')
def __str__(self):
return self.beneficiary_adhaar_name or self.beneficiary_id_name
my views.py
#login_required
def ApplyOnline(request):
return render(request,'users/applyonline.html')
#login_required
def personal_detail(request):
# ShowHideExample = request.POST.get('showHideExample',False)
beneficiary_adhaar_name=request.POST.get('beneficiary_adhaar_name')
adhaarno=request.POST.get('adhaarno')
adhaarcopy = request.FILES.get('adhaarcopy')
idcard=request.POST.get('idcard')
adhaar_eid=request.POST.get('adhaar_eid')
beneficiary_id_name=request.POST.get('beneficiary_id_name')
idno=request.POST.get('idno')
idcopy = request.FILES.get('idcopy')
apply_online = Personal_Detail(beneficiary_adhaar_name=beneficiary_adhaar_name,adhaarno=adhaarno,adhaarcopy=adhaarcopy,
idcard=idcard,adhaar_eid=adhaar_eid,beneficiary_id_name=beneficiary_id_name,idno=idno,idcopy=idcopy)
apply_online.save()
return render(request,'users/applyonline.html')
I don't know the problem that is causing this it was working fine when suddenly i did some changes with query to create a multi step form and when checked the database I was getting some null entries and when i clicked or tried to delete them I got error.I've included the image of null entries i was getting.
Basically your Model's __str__ method is returning None. Means both of the field's value is None. You need to return a string value from that method. For example:
class Personal_Detail(models.Model):
# rest of the code
def __str__(self):
return self.beneficiary_adhaar_name or self.beneficiary_id_name or str(self.pk)
I have the following code in my userprofile_list.html template:
{% extends "base.html" %}
{% block content %}
{% for users in userprofile_list %}
<a href="{% url 'users:user_profile' user.pk %}">
<div class="user-card">
<img class="profile-pic" src="{%if user.userprofile.profile_pic%}{{user.userprofile.profile_pic.url}}{%endif%}">
<p class="user-card-name">{{ users.pk }}</p>
<p class="user-card-name">{{ users.first_name }}</p>
<p class="user-card-type">{{ users.user_type }}</p>
</div>
</a>
{% endfor %}
{% endblock %}
Note the line <a href="{% url 'users:user_profile' user.pk %}">, I am using it elsewhere in the my app and when clicked it takes you to the profile of the currently logged-in user. However, I would instead like it to take you to the profile of whichever user you clicked on in the users list being created by the for loop. How do I change the url to do that?
I think what has to be done is that instead of getting the pk of the currently logged in user it has to instead get the pk of that specific user in the users list, which is then passed through to the url patterns (already working so I didn't posting it).
Note: If I'm not right with my logic on what has to happen thats fine just let me know what you need to see in order to help. Thank you.
Edit
base.html:
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<title>Evverest</title>
<meta name"viewport" content="width=device-width, initial-scale=1">
<meta charset="uft-8">
<link rel="shortcut icon" href="/images/favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Droid+Sans|Mukta+Mahee|Noto+Sans" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
</head>
<body>
<nav>
<div class="container">
<a class="brand" href="{% url 'index' %}">Evverest</a>
<div class="navbar">
<a class="nav-link" href="{% url 'index' %}">Home</a>
{% if user.is_authenticated %}
<a class="nav-link" href="{% url 'users:user_profile' user.id %}">
{{ user.username|capfirst }}
</a>
<a class="nav-link" href="{% url 'users:user_list' %}">All Members</a>
<a class="nav-link" href="{% url 'account_logout' %}">Logout</a>
{% else %}
<a class="nav-link" href="{% url 'account_login' %}?next=/">Login</a>
<a class="nav-link" href="{% url 'account_signup' %}?next=/">Register</a>
{% endif %}
</div>
</div>
</nav>
<div class="container">
<div class="content">
{% block content %}
{% endblock %}
</div>
</div>
</body>
</html>
I think you have a typo in that link. Try this:
<a href="{% url 'users:user_profile' users.pk %}">
You are using user.pk The loop variable is users, so you need to use users.pk, assuming that you have created a view to edit user_profile by getting pk of user_profile .
EDIT
Try this base.html:
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<title>Evverest</title>
<meta name"viewport" content="width=device-width, initial-scale=1">
<meta charset="uft-8">
<link rel="shortcut icon" href="/images/favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Droid+Sans|Mukta+Mahee|Noto+Sans" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
</head>
<body>
<nav>
<div class="container">
<a class="brand" href="{% url 'index' %}">Evverest</a>
<div class="navbar">
<a class="nav-link" href="{% url 'index' %}">Home</a>
{% if request.user.is_authenticated %}
<a class="nav-link" href="{% url 'users:user_profile' request.user.id %}">
{{ request.user.username|capfirst }}
</a>
<a class="nav-link" href="{% url 'users:user_list' %}">All Members</a>
<a class="nav-link" href="{% url 'account_logout' %}">Logout</a>
{% else %}
<a class="nav-link" href="{% url 'account_login' %}?next=/">Login</a>
<a class="nav-link" href="{% url 'account_signup' %}?next=/">Register</a>
{% endif %}
</div>
</div>
</nav>
<div class="container">
<div class="content">
{% block content %}
{% endblock %}
</div>
</div>