django-bootstrap-toolkit for my contact page - python

I'm new to django. I'm using django-bootstrap-toolkit for my contact page. It works fine when I test it locally. But I'm getting an error on my hosting server, while all other pages work just fine.
Exception Type: TemplateDoesNotExist
Exception Value: bootstrap_toolkit/form.html
Here is contact_us.html page
bootstrap_toolkit/form.html
{% extends 'base.html' %}
{% load bootstrap_toolkit %}
{% block content %}
<div id="wrap">
<div class="container">
<div class="page-header">
<h1 id="contact">Contact</h1>
</div>
<div class="form well" >
<h4 class="">Feedback</h4>
<p class="">Thank you for downloading BookxGeek. I look forward to hearing your feedback!</p>
<form action="." method="post" class="form" >
{% csrf_token %}
{% bootstrap_form form layout="vertical" %}
<br>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
<hr class="soft">
</div>
{% endblock %}

Related

Django-widget-tweaks Email address can't be entered error

I created a login form using Django-widget-tweaks, but I cannot enter any text in the email address field.
What is the solution?
Please help.
html
{% extends 'app/base.html' %}
{% load widget_tweaks %}
{% block content %}
<div class="card card-auto my-5 mx-auto">
<div class="card-body">
<h5 class="card-title tex-center">ログイン</h5>
<form method="post" class="form-auth">
{% csrf_token %}
<div class="form-label-group">
{% render_field form.login class='form-control' placeholder='Email' %}
</div>
<div class="form-label-group">
{% render_field form.password class='form-control' placeholder='Password' %}
</div>
<div class="buttton mx-auto">
<button class="btn btn-lg btn-primary btn-block mx-auto" type="submit">Login</button>
</div>
</form>
</div>
</div>
{% endblock %}
I can't enter my email address.

How to scroll lock a Django HTML Web Page

I am currently using a page that has a list of in-line forms
However when the user enters submits each form (line) they are sent back to the top of the page. This becomes really tedious as the users need to enter data quickly and can't when they need to scroll for 2 minutes every time they add an entry.
Does anyone know how to implement a scroll lock to stock this from happening
Views.py: Function:
class AvonleaView( View):
def get(self,request):
created_nums= AvonleaClass.objects.all().values('unitNumber')
Aprev = AvonleaClass.objects.all().order_by('-unitDateEntered')
# created_nums= AvonleaClass.objects.all()
print(created_nums )
created_nums =[int(i['unitNumber']) for i in created_nums]
print(created_nums )
form = AvonleaForm()
return render(request,"meter_readings/avonlea.html",{'form':form , 'created_nums':created_nums })
def post(self,request):
created_nums= AvonleaClass.objects.all().values_list('unitNumber')
print(created_nums)
form = AvonleaForm(request.POST)
if form.is_valid():
form.save()
return redirect('Avonlea')
messages.success(request , 'creates successfully ')
else:
return render(request, 'meter_readings/avonlea.html', {'form': form , created_nums:created_nums })
HTML page :
{% extends 'meter_readings/base.html' %}
{% block content %}
<!-- CSS only -->
<div class="container" font-size= 8px>
<center><h1>Avonlea Meter Readings</h1></center>
<br>
<head>
<meta name="viewport" content="width=device-width">
</head>
{% for unit_number in form.unitNumber %}
<h6>{{ error }}</h6>
<form class="form-group mt-4" method="post" {% if unit_number.data.value in created_nums %} style="background-color: rgb(231, 224, 224); " {% endif %} >
{% csrf_token %}
<div class="container">
<div class="row mb-3">
<div class="col">
<h5 style="font-size: 14px"> Unit number </h5>
{{ unit_number.data.value}}
</div>
<input type="hidden" name="unitNumber" value="{{unit_number.data.value}}">
<div class="col" id="prev{{unit_number.data.value}}" >
<h5 style="font-size: 14px"> Previous Reading </h5>
{{ previousReading }}
</div>
<div class="col" id="readings{{unit_number.data.value}}">
<h5 style="font-size: 14px"> Current Reading </h5>
{{ form.newReading }}
</div>
<div class="col" id="difference{{unit_number.data.value}}">
<h5 style="font-size: 14px"> Units Used </h5>
{{ form.difference }}
</div>
<div class="col" id="img{{unit_number.data.value}}">
{{ form.image }}
</div>
<div class="col">
<button id="form.id" class="btn btn-success " type="submit" {% if unit_number.data.value in created_nums %} disabled {% endif %} > Save</button>
</div>
</div>
</div>
</form>
{% endfor %}
<br>
<br>
If I understand correctly, you can add #<some_id> to the action attribute of your forms and when the page loads the browser will automatically put the element with the id="some_id" in view.
Example:
<form id="form1" action="#form2" method='POST'>...</form>
...
<form id="form2" action="" method='POST'>...</form>
If you submit #form1 when the page reloads the browser will scroll to #form2 even if it's at the bottom of the page.
Or if you only have one form, you can do:
<form id="form1" action="#form1" method='POST'>...</form>
EDIT:
<form id="form{{forloop.counter0}}" action="#form{{forloop.counter}}" class="form-group mt-4" method="post" {% if unit_number.data.value in created_nums %} style="background-color: rgb(231, 224, 224); " {% endif %} >

It keeps showing unknown tag error with {% for post in all_posts %} and {% endfor %} when i run it with flask

include "header.html" %}
<!-- Page Header -->
<header class="masthead" style="background-image: url('https://images.unsplash.com/photo-1470092306007-055b6797ca72?ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80')">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="site-heading">
<h1>Angela's Blog</h1>
<span class="subheading">A collection of Angela's random musings.</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
{% for post in all_posts %}
<div class="post-preview">
<a href="{{ url_for('show_post', index=post.id) }}">
<h2 class="post-title">
{{post.title}}
</h2>
<h3 class="post-subtitle">
{{post.subtitle}}
</h3>
</a>
<p class="post-meta">Posted by
{{post.author}}
on {{post.date}}</p>
</div>
<hr>
{% endfor %}
<!-- New Post -->
<div class="clearfix">
<a class="btn btn-primary float-right" href="#">Create New Post</a>
</div>
</div>
</div>
</div>
<hr>
{% include "footer.html" %}
It isn't show the website It keeps showing unknown tag error with {% for post in all_posts %} and {% endfor %} when i run it with flask. i cant add any more detail
It isn't show the website It keeps showing unknown tag error with {% for post in all_posts %} and {% endfor %} when i run it with flask. i cant add any more detail
It isn't show the website It keeps showing unknown tag error with {% for post in all_posts %} and {% endfor %} when i run it with flask. i cant add any more detail
It isn't show the website It keeps showing unknown tag error with {% for post in all_posts %} and {% endfor %} when i run it with flask. i cant add any more detail

Request in Flask from a Form in HTML is returning None Value, What should I Do?

I am getting no value on request in flask. It is returning None value.
I have tried changing the method but no use.
The flask code:
#app.route("/login/user/book")
def searchbook():
bookname=request.form.get("search")
return render_template("message.html",heading=bookname ,message=" ")
The webpage:
{% extends "layout.html" %}
{% block heading %}Welcome to BookSarkar{% endblock %}
{% block body %}
<p>Welcome {{ name }}</p>
<form action="{{ url_for('searchbook') }}" method="get" class="form-group">
<div class="form-group">
<input type="text" name="search" class="form-control col-md-6 mt-5 mx-auto" placeholder="Search books">
<p style="text-align:center;">
<button type ="submit" class="btn btn-primary mt-2 mx-auto">Search</button>
</p>
</div>
</form>
<div class="fixed-top m-2">
<a class="btn btn-outline-primary" href="{{ url_for('logout') }}" role="button" style="float:right;">Log out</a>
</div>
{% endblock %}
The message webpage:
{% extends "layout.html" %}
{% block heading %}{{ heading }}{% endblock %}
{% block body %}
{{ message }}
<a class="btn btn-primary" href="{{ url_for('index') }}" role="button">Return to Home Page</a>
{% endblock %}
The layout page has no bugs as all other pages are working fine. I expected the webpage to show the given input but it is showing None
request.form contains values submitted via post or put, while your form uses get. Try using request.args.get("search") instead of request.form.get("search")

How to handle AuthAlreadyAssociated at Python-auth/Django-Social? [duplicate]

This question already has answers here:
AuthAlreadyAssociated Exception in Django Social Auth
(5 answers)
Closed 9 months ago.
I use this python-social-auth/social-app-django to connect my web with social media
I want to ask how to handle errors when the same account is used to sign up?
For example, I signed up using facebook and I signed up again using twitter. both successfully registered into two separate accounts, when I logged in using my facebook and then on my account settings page, I want to connect my twitter that has been registered before it will display an error message
"AuthAlreadyAssociated at / oauth / complete / twitter /"
AuthAlreadyAssociated
This message appears after I authorize on the twitter redirect page when it gets redirected back to my web.
In short, how to deal with accounts that have been registered in other accounts?
This is my views.py:
#login_required
def settings(request):
user = request.user
try:
github_login = user.social_auth.get(provider='github')
except UserSocialAuth.DoesNotExist:
github_login = None
try:
twitter_login = user.social_auth.get(provider='twitter')
except UserSocialAuth.DoesNotExist:
twitter_login = None
try:
facebook_login = user.social_auth.get(provider='facebook')
except UserSocialAuth.DoesNotExist:
facebook_login = None
can_disconnect = (user.social_auth.count() > 1 or
user.has_usable_password())
return render(request, 'profile/settings.html', {
'github_login': github_login,
'twitter_login': twitter_login,
'facebook_login': facebook_login,
'can_disconnect': can_disconnect
})
And this is my settings.html template:
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block title %}Navhi Microblog - Profile{% endblock %}
{% block content %}
<div class="col-lg-12 mx-auto">
<br />
<div class="card">
<div class="card-body">
{% include 'profile/base_profile.html' %}
<!--Card Body goes here-->
<div class="card-body">
<div class="card">
<div class="card-body">
{% if github_login %}
{% if can_disconnect %}
<form method="post" action="{% url 'social:disconnect' 'github' %}">
{% csrf_token %}
<button class="btn btn-danger btn-block" type="submit">Disconnect from GitHub</button>
</form>
{% else %}
<p class="text-center" style="color: red">You must define a password for your account before disconnecting from Github.</<p class="text-center">
{% endif %}
{% else %}
<a class="btn btn-sm btn-social btn-github btn-block" href="{% url 'social:begin' 'github' %}?next={{ request.path }}">
<span class="fa fa-github"></span> Connect to Github
</a>
{% endif %}
</div>
</div>
<br />
<div class="card">
<div class="card-body">
{% if twitter_login %}
{% if can_disconnect %}
<form method="post" action="{% url 'social:disconnect' 'twitter' %}">
{% csrf_token %}
<button class="btn btn-danger btn-block" type="submit">Disconnect from Twitter</button>
</form>
{% else %}
<p class="text-center" style="color: red">You must define a password for your account before disconnecting from Twitter.</p>
{% endif %}
{% else %}
<a class="btn btn-sm btn-social btn-twitter btn-block" href="{% url 'social:begin' 'twitter' %}?next={{ request.path }}">
<span class="fa fa-twitter"></span> Connect to Twitter
</a>
{% endif %}
</div>
</div>
<br />
<div class="card">
<div class="card-body">
{% if facebook_login %}
{% if can_disconnect %}
<form method="post" action="{% url 'social:disconnect' 'facebook' %}">
{% csrf_token %}
<button class="btn btn-danger btn-block" type="submit">Disconnect from Facebook</button>
</form>
{% else %}
<p class="text-center" style="color: red">You must define a password for your account before disconnecting from Facebook.</p>
{% endif %}
{% else %}
<a class="btn btn-sm btn-social btn-facebook btn-block" href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}">
<span class="fa fa-facebook"></span> Connect to Facebook
</a>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
Thank you, I hope somebody can provide a solution for this, and sorry for my bad english.
Your question has been answered here:
AuthAlreadyAssociated Exception in Django Social Auth
Basically the answer is to override the default method process_exception() in the social_auth.middleware.SocialAuthExceptionMiddleware class, and add this middleware to your settings.py.
More on how to override here: How do I handle exceptions on Python Social Auth

Categories