I am pretty new to CSS, however I have a django modelformset_factory which i need to render and align all rendered fields in same line for each field, it has TextArea and Textinput, the problem as per the attached picture i tried to aligned all but they never get aligned together.
here my view:
from django.forms import modelformset_factory
def form_employee(request, employee_id):
employee = Employee.objects.get(pk=employee_id)
Employee_PM = PMF.objects.filter(badge=employee_id)
for pm in Employee_PM:
form_reference = pm.form_ref
emp_form = PMF_Form.objects.filter(form_ref=form_reference)
emp_summary = PMF_Summary.objects.filter(badge=employee_id)
PMF_formset = modelformset_factory(PMF_Form, fields=('objective','obj_desc','rating',), extra=0)
formset = PMF_formset(queryset=PMF_Form.objects.filter(form_ref=form_reference))
if request.method == "POST":
formset = PMF_formset(request.POST, queryset=PMF_Form.objects.filter(form_ref=form_reference))
if formset.is_valid():
formset.save()
return redirect('/')
for form in formset:
form.fields['objective'].widget.attrs['disabled'] = True
form.fields['obj_desc'].widget.attrs['disabled'] = True
context = {"Employee_PM":Employee_PM,"employee":employee,"emp_form":emp_form,"emp_summary":emp_summary,"formset":formset}
return render(request, 'PMS/form_employee.html',context)
\* {
padding: 2px;
margin: 0px;
margin-bottom: 4px;
background-color: black;
color: aliceblue;
box-sizing:border-box;
flex-direction: column;
}
.container {
background-color: black;
}
body {
background-color: black;
}
.form2 {
margin: 20px;
box-sizing: border-box;
width:100%;
resize: none;
overflow-wrap: break-word;
/\* display: flex; \*/
margin: auto;
}
input {
/\* width: 50%; \*/
display: inline-block;
width:15rem;
height: 70px;
position: relative;
}
textarea {
width: 50rem;
height: 70px;
resize: none;
}
}
span {
justify-content: center ;
display: flex;
}
<div class="container">
<h2>formset</h2>
<form method="POST" class="form2" enctype="multipart/form-data">
{% csrf_token %}
{{ formset.management_form }}
{% for form in formset %}
{% for field in form %}
{{field}}
{% endfor %}
{% endfor %}
<button type="submit">Submit</button>
</form>
a photo from the output
the main problem is mainly I need to give them all the same height and align them to same line
i think you should use css property called 'vertical-align'
Related
I am trying to build a paywall using HTML and CSS in Django, but somehow the CSS that is supposed to fade portions of the text does not render. Here is what I have:
<style>
.adjust-image {
display: block;
width: auto;
max-width: 100%;
max-height: 1000px;
}
.blur-text {
filter: blur(5px);
user-select: none;
pointer-events: none;
}
.fade-out {
user-select: none;
position: relative;
}
.fade-out:after {
content: "";
height: 75%;
width: 100%;
position: absolute;
bottom: 0;
left: 0;
background: linear-gradient(to bottom, rgba(255,255,255,0), #fff);
}
#paywall-wrapper {
padding: 35px;
border-radius: 5px;
position: relative;
margin-bottom: 30px;
box-shadow: 0px 0px 20px -1px rgba(0,0,0,0.20);
}
#paywall-wrapper * {
text-align: center;
}
#paywall-wrapper .btn {
left: 50%;
transform: translateX(-50%);
position: relative;
}
</style>
<div class="display-margins">
<div>
<h5>{{solution.questionToProblem}}</h5>
<h6><b>Solution</b></h6>
{% if request.user.is_anonymous or solution.free != True and request.user.is_subscriber != True %}
<p class= "format-paragraph fade-out:after">{{solution.solutionToProblem|safe}}</p>
<div id="paywall-wrapper">
<h4>Premium Subscription</h4>
<p>To view this solution, get our subscription for just <strong>$17</strong>.</p>
<a class="btn btn-primary text-light" href = "{% url 'subscribe' %}">Subscribe</a>
</div>
{% else %}
<p class="noselect format-paragraph">{{solution.solutionToProblem|safe}}</p>
{% for s in solution_images %}
<img class = "adjust-image noselect" src="{{ s.photo.url }}">
<br></br>
{% endfor %}
{% endif %}
{% render_comments solution request %}
<br class= "extra_spacing"></br>
</div>
</div>
Ideally, the text for paywall is supposed to fade out like this:
But it doesn't render when I have template variables in my <p> tags:
Surprisingly enough, if I type out content in my <p> tags manually, it works. But when I use <p>{{random content}}</p>, it doesn't work.
What am I doing wrong with my CSS or my HTML when I say <p class= "format-paragraph fade-out:after">{{solution.solutionToProblem|safe}}</p>?
Make sure when you want CSS integrated in Django, and you have HTML in your template variable, use:
{{put_your_template_variable|striptags}}
instead of safe.
I'm trying to override the parent settings of a dropdown menu using a child class in CSS. Unfortunately, when I try to do this it gives me an "unknown property name" error on the child class, even though I use the exact same property on the parent class.
The CSS code looks like:
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
overflow: hidden;
min-width: 160;
min-heigth: 100;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
left:20%;
}
.test {
min-width: 1080;
min-heigth: 480;
}
.dropdown:hover .dropdown-content {
display: inline-block;
}
And the HTML code (django template format) looks like:
{% for info in infos %}
<div class="dropdown">
dropdown item
<div class="dropdown-content">
{% if info.2 == "img" %}
<!-- display image -->
{% elif info.2 == "gif" %}
<div class="test">Gifs and Videos are disabled for preview.</div>
{% endif %}
</div>
</div>
{% endfor %}
In which info.2 will always contain either the string "gif" or "img". I have not yet implemented the image yet.
However, if I use inspect element I get the following error:
Which does not make any sense to me, as the css within the dropdown-content class does correctly work. What is going wrong here?
Because 1080 can be 1080 potatoes or elephants, You need to specifiy px or whatever unit you prefer
I have an overlay containing a django form and the background image doesn't show up. I have a silhouette image in the background and that fills the page, and ideally moves with the page size. Then a table on top in the centre of it containing my form which I have tried to make transparent.
I was blindly fiddling with the css yesterday and it has disappeared!
{% extends 'prodman/basenew.html' %}
{% load staticfiles %}
{% block pagetitle %}Time and Expenses{% endblock %}
{% block content %}
<iframe name="hiddenFrame" class="hide"></iframe>
<div id="overlay">
<form id= "person-form" target='hiddenFrame' method = 'POST' action="" class="overlay-form" enctype="multipart/form-data">{% csrf_token %}
<table id="add-person-form" class="overlay-table">
<tr></br></br>{{ personform.first_name }}</tr>
<tr></br></br>{{ personform.surname }}</tr>
<tr></br></br>{{ personform.email }}</tr>
<tr></br></br>{{ personform.position }}</tr>
<tr></br></br>{{ personform.contract_type }}</tr>
<tr></br></br>{{ personform.mentor }}</tr>
<tr></br></br><font color="white">Assign as a coach? </font>{{ personform.make_person_coach }}</tr>
</table>
</br>
<input type = "submit" id = "save" value = "Add person">
</br>
</br>
<strong>Click here to [<a href='#' onclick='overlay()'>close</a>]</strong>
</form>
</div>
<a href='#' class='class1' onclick='overlay()'>Add person</a>
<p>Some more html here....</p>
{% endblock %}
In my basenew.html I have
{% load staticfiles %}
<head>
<link rel='stylesheet' href="{% static 'tande/newtimesheets.css' %}" type='text/css' media='all'/>
</head>
...
Here is my stylesheet
#overlay {
visibility: hidden;
position: absolute;
left: 0px;
top: 0px;
width:100%;
height:100%;
text-align:center;
z-index: 1000;
background-image:url('{% static 'tande/images/silhouette.png' %}');
background-repeat: no-repeat;
background-size: 90%;
background-position: center;
}
#overlay div {
width:800px;
margin: 100px auto;
background: #cccccc;
border: 1px solid #000;
padding:15px;
text-align:center;
}
form.overlay-form {
width:800px;
margin: 350px auto;
}
table.overlay-table tr td {
background: rgb(54, 25, 25);
background: rgba(54, 25, 25, 0);
border-style: none;
margin-right: 40%;
margin-bottom: 30%;
position: relative;
text-align: center;
width: 800px;
}
add-person {
text-align: right;
margin-right: 10px;
width: 10px;
}
body {
height:100%;
margin:0;
padding:0;
}
Just in case it's helpful here is how the overlay is triggered:
function overlay() {
el = document.getElementById("overlay");
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
Thanks!
I'm creating a django form and I can't seem to access each field's widget to style it differently when there's an error or when the field is required (eg: highlight the field's box).
HTML:
{% block content %}
<form action="" method="POST" class="form"> {% csrf_token %}
{% for field in form %}
<div class="fields-container">
<p class="label">{{ field.label }}</p>
{{ field }}
</div>
{{ field.errors }}
{% endfor %}
<button type="submit" id="form-button">Submit</button>
</form>
{% endblock %}
CSS:
.label {
margin: 0 5px 0 0;
width: 20%;
text-align: left;
}
#id_full_name, #id_email, #id_message {
margin: 0;
flex: 1 1;
}
#id_message {
resize: none;
overflow: auto;
}
.errorlist { /*default css class for form errors*/
color: 999999;
font-size: 75%;
font-weight: bold;
list-style: none;
margin-bottom: 5px;
align-self: flex-start;
}
I've been accessing and styling the widgets using #id_fieldname, but I've tried the following and it didn't work:
#id_fieldname.required, id_fieldname.error { border: 2px solid red; }
Thanks in advance!
You could add a class 'required' in your container <div>:
<div class="fields-container {% if field.field.required %}required{% endif %}">
Using django form methods form.as_p, form.as_ul, form.as_table, this would be done automatically if you declare a specific css class for required fields in your Form, for example:
class myForm(forms.Form):
required_css_class = 'required'
...
More in documentation
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm building a personal site using Flask and SQLAlchemy. I've been having problems getting my /login route to display properly. It worked, then I changed my .page class margin in my CSS from auto and then back again, and then my login forms stopped displaying entirely.
What I can't figure out is what I did to make them disappear -- I cut my server off a couple of times and restarted it, and the page didn't load. When I came back quite a bit later, I restarted my server again and the login page loaded. I thought that it was "solved", but then when I came back a couple of hours later, the login page won't load again. All of my other extended HTML pages load correctly, just not my login page with my login forms.
I don't have a link anchor for the login page -- I just access it by typing out the route (/login).
Here is my relevant code:
views.py (auth blueprint)
from flask import render_template, redirect, request, url_for, flash
from flask.ext.login import login_user
from . import auth
from ..models import User
from .forms import LoginForm
#auth.route('/login', methods =['GET', 'POST'])
def login():
form = LoginForm()
"""if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data.first())
if (user is not None) and user.verify_password( form.password.data):
login_user(user, form.remember_me.data)
return redirect(request.args.get('next') or url_for('main.index'))
flash('Invalid username or password.')"""
return render_template('auth/login.html', title = "Log in", form = form)
layout.html
<!DOCTYPE html>
<title>
{% block title %}
perSimmons
{% endblock %}
</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
<body>
<div>
<ul id="nav">
<li id="banner">{ perSimmons }</li>
<li id="links">Blog</li>
<li id="links">Resume</li>
<li id="links">Contact</li>
<li id="links">About</li>
</ul>
<br>
<div class=page>
{% block content %}
{% endblock %}
</div>
</div>
</body>
login.html
{% extends "layout.html" %}
{% block title %}perSimmons - {{title}} {% endblock %}
{% block content %}
<div class=page-header>
<h3>Admin Login</h3>
</div>
<form action="" method="post" name="login">
<p id="user-login">
Username:<br>
{{form.email}}<br>
Password:<br>
{{form.password}}<br>
</p>
<p><input type="submit" value="Log in">{{form.remember_me}}Stay signed-in </p>
</form>
{% endblock %}
style.css
#font-face {
font-family: 'SourceCodeProRegular';
src: url('fonts/SourceCodePro-Regular.otf.woff');
src: local('SourceCodePro Regular'), local('SourceCodePro'), url('fonts/SourceCodePro-Regular.otf.woff') format('truetype');
}
body { font-family: 'SourceCodeProRegular'; background: #CC3300; }
a, h2 { color: #CC3300; }
h1, h2 { font-family: 'SourceCodeProRegular'; margin: 0; }
h1 { border-bottom: 2px solid #CC3300; }
h2 { font-size: 2em; font-weight: bold; }
h3 { color: #CC3300;}
li { color: #CC3300;}
dl { color: #CC3300;}
p { color: #CC3300;}
#nav {
width: 100%;
float: left;
margin: 0 0 1em 0;
padding: 0;
list-style: none;
background-color: #CC3300;
border-bottom: 5px solid #999966;
border-top: 5px solid #999966;
border-left: 5px solid #999966;
border-right: 5px solid #999966;
}
#nav #banner { font-weight:bold; }
#nav li { float:left; }
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
color: #FFFF66;
border-right: 2px solid #999966;
}
#nav li a:hover {
color:#CC3300;
background-color: #FFFF66;
}
.page {
margin: 2em auto;
width: 55em;
border: 5px solid #999966;
padding: 0.8em;
background: #FFFF66;
}
.entries {
list-style: none;
margin: 0;
padding: 0;
}
.entries li { margin: 0.8em 1.2em; }
.entries li h2 { margin-left: -1em;}
.add-entry {
font-size: 0.9em;
border-bottom: 1px solid #CC3300;
}
.flash {
font-color: #999966;
font-family: 'SourceCodeProRegular';
background: #CC3300;
padding: 0.5em;
border: 1px solid #aacbe2;
}
.error {
background: #f0d6d6;
padding: 0.5em;
}
It looks like you're missing the form.csrf_token.
My forms disappeared sporatically without this present. Try the following:
login.html
{% extends "layout.html" %}
{% block title %}perSimmons - {{title}} {% endblock %}
{% block content %}
<div class=page-header>
<h3>Admin Login</h3>
</div>
<form action="" method="post" name="login">
{{form.csrf_token}}
<p id="user-login">
Username:<br>
{{form.email}}<br>
Password:<br>
{{form.password}}<br>
</p>
<p><input type="submit" value="Log in">{{form.remember_me}}Stay signed-in </p>
</form>
{% endblock %}
Note the addition of the {{form.csrf_token}} line.
You need to provide this for the form to render correctly if you don't use the wtf.quickform method.
The correct route for login.html in the auth blueprint is /auth/login -- not /login. Everything loaded correctly when I made this change.