I was previously using 0.6 version of django-registration.Now I upgraded to 0.8 ,and some issues are cropping up in my webapp
I have in the templates/registration folder ,these files needed for register(among others)
activation_complete.html
activation_email.txt
activation_email_subject.txt
registration_form.html
registration_complete.html
The registration_form.html is
{% extends "registration/auth_base.html" %}
{% block content %}{{block.super}}
<div class="subtitle short">Register</div>
<div id="registerform" class="box half">
<form action="/myapp/account/register/" method="POST">{% csrf_token %}
{% if form.non_field_errors %}
{{ form.non_field_errors }}
{% endif %}
<fieldset class="registerfields">
<p><label for="id_username">Username:</label> {{ form.username }}</p>
{% if form.username.errors %}<p class="error">{{ form.username.errors }}</p>{% endif %}
<p><label for="id_email">EmailAddress:</label>{{ form.email }}</p>
{% if form.email.errors %}<p class="error">{{ form.email.errors }}</p>{% endif %}
<p><label for="id_password1">Password:</label>{{ form.password1 }}</p>
{% if form.password1.errors %}<p class="error">{{ form.password1.errors }}</p>{% endif %}
<p><label for="id_password2">Password(again):</label>{{ form.password2 }}</p>
{% if form.password2.errors %}<p class="error">{{ form.password2.errors }}</p>{% endif %}
<p>
<input type="submit" value="Submit" />
</p>
</fieldset>
</form>
</div>
{% endblock %}
The template registration_complete.html is as below
{% extends "registration/auth_base.html" %}
{% block content %}{{block.super}}
<p id="message">Registration Complete! Check your email</p>
{% endblock %}
Also here is the auth_base.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Myapp{% block title %} {% endblock %}</title>
<LINK REL=StyleSheet HREF="{{MEDIA_URL}}css/myapp.css" TYPE="text/css" MEDIA="screen, print"/>
<link rel="shortcut icon" href="{{ MEDIA_URL }}img/myapp-icon.ico"/>
</head>
<body>
<div id="content">
{% block content %}
{% endblock %}
</div>
<div id="sidebar">
<h3> page info </h3>
{% block whatis %}
{% endblock %}
</div>
<div id="homelnk">
<img class="centerpage" src="{{ MEDIA_URL }}img/home.png">
</div>
</body>
</html>
But when I submit a new user details for registration,I am not getting this registration_complete page.I still get a registration form with blank fields
Still,the activation link is sent to the email , and I am able to login as the new user..Why is the registration_complete page not shown?This used to work in the older version of django-registration ..I couldn't find anything in the upgrade guide regarding the templates..
Any advice appreciated
I use this template for registration_form.html:
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form method="post" action=".">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans 'Submit' %}" />
</form>
{% endblock %}
You can find more of those here :
https://github.com/nathanborror/django-registration/tree/master/registration/templates/registration
Related
I am attempting to learn Django but keep receiving the error " 'endfor', expected 'endblock'. Did you forget to register or load this tag? " when I add the {% for key,value in
price.DISPLAY.items %} {{ key }} {% endfor %} part of the code. How can I fix this? Any help would be great thanks.
home.html
{% extends 'base.html' %} {% block content %} {% for key,value in
price.DISPLAY.items %} {{ key }} {% endfor %}
<br />
<br />
{{ price.DISPLAY }}
<div class="jumbotron">
<h1 class="display-4">Welcome</h1>
</div>
<div class="container">
<div class="row">
{% for info in api.Data %}
<div class="card" style="width: 18rem">
<img src="{{info.imageurl}}" class="card-img-top" alt="{{info.source}}" />
<div class="card-body">
<h5 class="card-title">{{info.title}}</h5>
<p class="card-text">{{info.body}}</p>
<a href="{{info.url}}" class="btn btn-secondary" target="_blank"
>Read more</a
>
</div>
</div>
{% endfor %}
</div>
</div>
{{ api.Data }} {% endblock content %}
A template tag should not span multiple lines. You should write the {% for … %} tag on a single line:
{% extends 'base.html' %} {% block content %}
{% for key,value in price.DISPLAY.items %} {{ key }} {% endfor %}
…
{% endblock content %}
I want to build a website with Flask and WTForms. But I cannot get the text input to work (The page will not let me enter any text into the boxes). Can you show me what is wrong?
This is what the page looks like:
This is the form I created with WTForms
from flask_wtf import FlaskForm
from wtforms import SubmitField, IntegerField
from wtforms.validators import DataRequired, NumberRange, EqualTo
class RequestDataForm(FlaskForm):
feature_count = IntegerField('Number of features', validators=[DataRequired(), NumberRange(min=1, max=50)])
effective_rank = IntegerField('Effective Rank', validators=[DataRequired(), NumberRange(min=1, max=EqualTo(feature_count))])
noise = IntegerField('Noise', validators=[DataRequired(), NumberRange(min=0, max=1)])
submit = SubmitField('Submit')
This is the layout.html
<!DOCTYPE html>
<html>
<style>
</style>
<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">
</head>
<body>
<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 page_content %}{% endblock %}
</div>
</div>
</main>
</body>
</html>
and this is my page.html
{% extends 'layout.html' %}
{% block page_content %}
<div class="content-section">
<form method="POST" action="">
{{ form.hidden_tag() }}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Fill with values.</legend>
<div class="form-group">
{{ form.feature_count.label(class="form-control-label") }}
{{ form.feature_count.label(class="form-control form-control-lg") }}
</div>
<div class="form-group">
{{ form.effective_rank.label(class="form-control-label") }}
{{ form.effective_rank.label(class="form-control form-control-lg") }}
</div>
<div class="form-group">
{{ form.noise.label(class="form-control-label") }}
{{ form.noise.label(class="form-control form-control-lg") }}
</div>
</fieldset>
<div class="form-group">
{{ form.submit(class="btn btn-outline-info") }}
</div>
</form>
</div>
{% endblock page_content%}
According to your HTML you are only outputting the label for each form element not the element itself. Try updating them all to:
<div class="form-group">
{{ form.noise.label(class="form-control-label") }}
{{ form.noise(class="form-control form-control-lg") }}
</div>
Hi everyone I am using Django CMS in my Site, I create a template for a page and now using ajax to load a index.html in a section of this template...
Everything work fine ... but my index html call a style.css file and hpc.js file, that when I load by ajax I don't see its.
I use this to load file in my index.html
{% addtoblock "css" %}
<link rel="stylesheet" type="text/css" href="{% static 'health/css/stylehealth.css' %}" />
{% endaddtoblock %}
and this for my js.file
{% addtoblock "js" %}
<script src="{% static 'health/js/health.js' %}"></script>
{% endaddtoblock %}
my index.html
{% load cms_tags menu_tags sekizai_tags %}
{% load static %}
{% block title %}{% page_attribute "page_title" %}{% endblock title %}
{% block content %}
{% placeholder "content" %}
{% addtoblock "css" %}
<link rel="stylesheet" type="text/css" href="{% static 'health/css/stylehealth.css' %}" />
{% endaddtoblock %}
<div class="selector_healthApp">
<div class="selector_area">
<div class="row">
<form action="#">
{% for list in new_object_list %}
<div class="col-xs-3">
<select class="form-control" id="item_project">
<option>{{ 'Select Categoty' }}</option>
{% for item_list in list.select_opc %}
<option value="{{ list.url }}">{{ item_list }}</option>
{% endfor %}
</select>
</div>
<div class="col-xs-3">
<input type="text" class="form-control" id="start_rank" value="{{ list.start }}" placeholder="Start Rank">
</div>
<div class="col-xs-3">
<input type="text" class="form-control" id="display_count" value="{{ list.count }}" placeholder="Display Count">
</div>
<div class="col-xs-3">
<input type="submit" class="btn btn-primary execute_value" name="" value="Update">
</div>
{% endfor %}
</form>
</div>
</div>
</div>
<div class="healthChart">
<div class="container">
<div class="row">
<div class="graphic"></div>
</div>
</div>
</div>
{% addtoblock "js" %}
<script src="{% static 'health/js/health.js' %}"></script>
{% endaddtoblock %}
{% endblock content %}
so all tags like this {% %} don't load in a page.
any idea how to load this file...
Thanks in advance!
(A) If you need to be able to load the index.html regularly as well as via AJAX:
Use {% extends parent %} and set the parent variable depending on whether the request is an AJAX request or not.
The parent for the regular request is the complete page <html></html> with all resources so that it can be rendered whole.
(B) If you always ever use this template for rendering the response to that AJAX request only, don't need to differentiate between the parents.
The parent for the AJAX request only needs to contain the snippet that is in your block content including all required resources. You might even not need the content block directives. It depends on what you want to add to that snippet.
To use sekizai inside that partial template, however, you need to add a render_block directive for CSS and JS. And thus, these warnings apply:
{% render_block %} tags must not be placed inside a template tag block
(a template tag which has an end tag, such as {% block %}...{%
endblock %} or {% if %}...{% endif %}).
If the {% addtoblock %} tag is used in an extending template, the tags
must be placed within {% block %}...{% endblock %} tags.
http://django-sekizai.readthedocs.io/en/latest/#handling-code-snippets
So, a very simplistic solution for your code would be:
{% load cms_tags menu_tags sekizai_tags static %}
{# this won't work, because there is no parent template defining this block. Use JS to update the title #}
{# block title %}{% page_attribute "page_title" %}{% endblock title #}
{# e.g. send an element with ID that can be replaced in the title #}
{# do include the CSS and JS elements #}
{% render_block "css" %}
{% placeholder "content" %}
{% addtoblock "css" %}
<link rel="stylesheet" type="text/css" href="{% static 'health/css/stylehealth.css' %}" />
{% endaddtoblock %}
{# use the element ID to replace the html #}
<div id="index-container" class="selector_healthApp">
<div class="selector_area">
<div class="row">
<form action="#">
{% for list in new_object_list %}
<div class="col-xs-3">
<select class="form-control" id="item_project">
<option>{{ 'Select Categoty' }}</option>
{% for item_list in list.select_opc %}
<option value="{{ list.url }}">{{ item_list }}</option>
{% endfor %}
</select>
</div>
<div class="col-xs-3">
<input type="text" class="form-control" id="start_rank" value="{{ list.start }}" placeholder="Start Rank">
</div>
<div class="col-xs-3">
<input type="text" class="form-control" id="display_count" value="{{ list.count }}" placeholder="Display Count">
</div>
<div class="col-xs-3">
<input type="submit" class="btn btn-primary execute_value" name="" value="Update">
</div>
{% endfor %}
</form>
</div>
</div>
</div>
<div class="healthChart">
<div class="container">
<div class="row">
<div class="graphic"></div>
</div>
</div>
</div>
{% render_block "js" %}
{% addtoblock "js" %}
<script src="{% static 'health/js/health.js' %}"></script>
{% endaddtoblock %}
I have created a link to the Password Change Form using:
{% trans 'Change password' %}
And included it in urls.py as:
from django.contrib.auth import views as auth_views
url(r'^password_change', auth_views.password_change, {"template_name": "web/password_change_form.html"}, name='web_password_change'),
My Password Change Form is :
{% extends "base_site.html" %}
{% load i18n static bootstrapped_goodies_tags %}
{% load url from future %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %}
{% block breadcrumbs %}
<ul class="breadcrumb">
<li>{% trans 'Home' %}</li>
<li>{% trans 'Password change' %}</li>
</ul>
{% endblock %}
{% block title %}{% trans 'Password change' %}{% endblock %}
{% block content_title %}<a class="navbar-brand">{% trans 'Password change' %}</a>{% endblock %}
{% block content %}<div id="content-main">
<form class="form-horizontal" action="" method="post">{% csrf_token %}
{% if form.errors %}
<div class="alert alert-danger">
{% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
</div>
{% endif %}
<div class="alert alert-info">{% trans "Please enter your old password, for security's sake, and then enter your new password twice so we can verify you typed it in correctly." %}</div>
<fieldset class="_module _aligned wide">
<div class="form-group">
<div class="control-label col-sm-2">
{{ form.old_password.label_tag }}
</div>
<div class="controls col-sm-10">
{% dab_field_rendering form.old_password %}
{% if form.old_password.errors %}<span class="text-danger">{{ form.old_password.errors|striptags }}</span>{% endif %}
</div>
</div>
<div class="form-group">
<div class="control-label col-sm-2">
{{ form.new_password1.label_tag }}
</div>
<div class="controls col-sm-10">
{% dab_field_rendering form.new_password1 %}
{% if form.new_password1.errors %} <span class="text-danger">{{ form.new_password1.errors|striptags }}</span>{% endif %}
{% if form.new_password1.help_text %}<span class="text-info">{{ form.new_password1.help_text }}</span>{% endif %}
</div>
</div>
<div class="form-group">
<div class="control-label col-sm-2">
{{ form.new_password2.label_tag }}
</div>
<div class="controls col-sm-10">
{% dab_field_rendering form.new_password2 %}
{% if form.new_password2.errors %} <span class="text-danger">{{ form.new_password2.errors|striptags }}</span>{% endif %}
{% if form.new_password2.help_text %}<span class="text-info">{{ form.new_password2.help_text }}</span>{% endif %}
</div>
</div>
</fieldset>
<div class="form-actions">
<div class="controls col-sm-offset-2 col-sm-10">
<input type="submit" value="{% trans 'Change my password' %}" class="default btn btn-primary" />
</div>
</div>
<script type="text/javascript">document.getElementById("id_old_password").focus();</script>
</form></div>
{% endblock %}
The problem is :
It works for all web users, but if I login as admin and then change the password, say if the original password is:'admin'...Now I change it to '1234', it works and I can login again.
But when I again go to change_password and try to change from '1234' to something else, it gives 'Incorrect Old Password'.
On debugging, I found that the POST request received has the old_password field value as 'admin' while I have typed '1234'.
When I tried to add another field on the html page and updated the old_password section as below:
<div class="form-group">
<div class="control-label col-sm-2">
{{ form.old_password.label_tag }}
</div>
<div class="controls col-sm-10">
{% dab_field_rendering form.old_password %}
{{ form.old_password }}
{% if form.old_password.errors %}<span class="text-danger">{{ form.old_password.errors|striptags }}</span>{% endif %}
</div>
</div>
It works perfectly fine and receives the correct request, but I can't ask user to enter the old password two times.
I can edit a parent child relationship using the TablularInline and StackedInline classes, however I would prefer to list the child relationships as a change list as there is a lot of information and the forms are too big. Is there an inline change list available in DJango admin or a way or creating one?
There's no such functionality built in, but I don't think it would be hard to create your own AdminInline subclass (and an accompanying template for it) that would do this. Just model it off TabularInline, but display fields' data directly instead of rendering form fields.
So I was actually able to achieve this with quite the hack. Django Admin needs some updates and InlineAnything would be one.
Download Library: https://github.com/smartlgt/django-fakeinline
class MyInlineTest(FakeInline):
def __init__(self, parent_model, admin_site):
super().__init__(parent_model, admin_site)
self.template = Template('')
self.admin_site = admin_site
def get_fields(self, request, obj=None):
dpaa = DisplayProductAccessAdmin(DisplayProductAccess, self.admin_site)
dpaa.change_list_template = 'test.html'
self.template = Template(dpaa.changelist_view(request, {}).rendered_content)
return FakeInline.get_fields(self, request, obj=obj)
Then in your test.html, take most of the contents of the change_list.html from Django. Since we're using Jazzmin let's go with that.
{% load i18n admin_urls static admin_list jazzmin %}
{% block extrastyle %}
<link rel="stylesheet" href="{% static 'vendor/select2/css/select2.min.css' %}">
{% if cl.formset or action_form %}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
{% endif %}
{{ media.css }}
{% if not actions_on_top and not actions_on_bottom %}
<style>
#changelist table thead th:first-child {width: inherit}
</style>
{% endif %}
{% endblock %}
{% block extrahead %}
{{ media.js }}
{% endblock %}
{% block content %}
<div class="col-12">
<div class="card card-primary card-outline">
<div class="card-header">
<h4 class="card-title">{{ title }}{% block pretitle %}{% endblock %}</h4>
<div class="card-tools form-inline">
{% block date_hierarchy %}{% if cl.date_hierarchy %}{% date_hierarchy cl %}{% endif %}{% endblock %}
{% block search %}
{% search_form cl %}
{% endblock %}
</div>
</div>
<div class="card-body">
<form id="changelist-form" method="post"{% if cl.formset and cl.formset.is_multipart %}enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
<div id="content-main">
{% if cl.formset and cl.formset.errors %}
<p class="errornote">
{% if cl.formset.total_error_count == 1 %}
{% trans "Please correct the error below." %}
{% else %}
{% trans "Please correct the errors below." %}
{% endif %}
</p>
{{ cl.formset.non_form_errors }}
{% endif %}
<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
<div class="row">
<div class="col-12">
{% if cl.formset %}
<div>{{ cl.formset.management_form }}</div>
{% endif %}
{% block result_list %}
<div class="row">
<div class="col-12 col-sm-8">
{% if action_form and actions_on_top and cl.show_admin_actions %}
{% admin_actions %}
{% endif %}
</div>
<div class="col-12 col-sm-4">
{% block object-tools %}
{% block object-tools-items %}
{% change_list_object_tools %}
{% endblock %}
{% endblock %}
</div>
</div>
<hr/>
{% result_list cl %}
{% if action_form and actions_on_bottom and cl.show_admin_actions %}
<div class="row">
<div class="col-12">
{% admin_actions %}
</div>
</div>
{% endif %}
{% endblock %}
</div>
</div>
<div class="row">
{% block pagination %}{% pagination cl %}{% endblock %}
</div>
</div>
</div>
</form>
</div>
</div>
<br class="clear"/>
</div>
{% endblock %}
{% block extrajs %}
<script type="text/javascript" src="{% static 'vendor/select2/js/select2.min.js' %}"></script>
<script type="text/javascript" src="{% static 'jazzmin/js/change_list.js' %}"></script>
{% endblock %}