Django-Registration-Redux doesn't see my templates/registration templates - django-registration

I am using Django 1.10. Technically this post is regarding Django-registration-redux but SO wouldnt let me create a new tag to post the question. Django-registration-redux doesnt see the registration templates. I copied all the templates into a folder called "registration" inside of my templates folder. I dont get an error though. For example, when I go to /accounts/register it renders some form but it isn't the one from my templates/register folder. Im not sure what I am doing wrong. I have even gone as far as to delete the templates/registration folder entirely and I dont even get an error. I read some similar posts where people had to move the registration to the top of the installed apps so it wouldnt use the admin forms which I tried and didnt help. So far nothing has changed. All the templates do extend base.
So Im guessing I have configured something wrong. It's weird. All the functionality is there but its just not using my templates. Sorry if its a dumb question but I would appreciate some help!
pip freeze
Django==1.10
django-crispy-forms==1.6.0
django-registration-redux==1.4
INSTALLED_APPS = [
'registration',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# third party
'crispy_forms',
# my apps
'todo',
]
# Django registration redux settings
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_OPEN = True
REGISTRATION_AUTO_LOGIN = True
LOGIN_REDIRECT_URL = '/' # The page you want users to arrive at after they successful log in
LOGIN_URL = '/accounts/login/'
SITE_ID = 1
Here is my /templates/registration/registration_form.html
{% extends "base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
<div class='row'>
<div class='col-sm-6 col-sm-offset-3'>
<h1>Register for free!</h1>
<form method="post" action=".">
{% csrf_token %}
{{ form|crispy }}
<input class='btn btn-block btn-primary' type="submit" value="{% trans 'Join' %}" />
</form>
</div>
</div>
<hr/>
<div class='row'>
<div class='col-sm-6 col-sm-offset-3 text-align-center'>
<p>Need to Login?</p>
</div>
</div>
{% endblock %}
this is a screenshot showing the form I see at accounts/register

In settings.py you have to place your app above the 'registration' app. It seems the order the apps are listed in the settings.py file determines which templates are being used.

Next time try making a directory relating to your app's name in the app templates folder. For instance, if you have an app called "register" call the folder "register" in the templates folder of your app and then put all your templates in there. This would prevent templates named index.html in both app templates folder and the main project templates folder from conflict with each other.

Related

Twig: add content in the footer using extends makes extended code appear twice

To my understanding, by using twig's extends method, it should be possible to add code to the footer from within a template that is included anywhere else.
Like if we render the main page and have a <form> there in a template edit_form.html.twig and we know we need special javascript here (only for that form) so we decide to add this javascript tags in the footer at the end of the page like this:
edit_form.html.twig
{% block edit_form %}
<form id="editForm">
<!-- form html here -->
</form>
{% endblock edit_form %}
{{ include('edit_form_js.html.twig') }}
We want this javascript to be at the end of the page:
edit_form_js.html.twig
{% extends "footer.html.twig" %}
{% block js %}
{{ parent() }}
<script>
// special js code only needed for the <form>
</script>
{% endblock js %}
footer.html.twig
{% block js %}
<script src="jquery.js"></script>
{% endblock js %}
But doing this does not add the custom form javascript at the end after the jquery inclusion but results in the block js being twice on the page (after the form and in the footer)
Is my understanding of twigs extends wrong?
Q: Is there any way to add code from anwywhere to the footer?
Included templates don't know anything from the template it's being called from. There for an included template cannot alter a block from that said template. You might want to have a look at the deferred extension

Image not displaying using Craft CMS [duplicate]

This question already has answers here:
How can I display the image from the related entry for each entry in craft CMS and twig?
(2 answers)
Closed 10 months ago.
I'm new to using Craft CMS and trying to successfully make an image display.
I have set up a field with the handle heroImage and this is the code I have within the template.
{% set image = entry.heroImage.one() %}
<div>
<img src="{{ image.getUrl }}">
</div>
However, the image is not displaying in the browser.
I think you forgot to add parenthesis after getUrl as it was a function (method). You can use below code for that.
{% set image = entry.heroImage.one() %}
<div>
<img src="{{ image.getUrl() }}">
</div>
Users encountering this may want to check folder permissions. I encountered this in a site migration situation.
Try this
<img src="https://dev-craft3-384fa3039dfb.hyperlane.co/uploads/scren1.png" referrerpolicy="no-referrer" alt="ALI TEST LIVE LINK" />

Digg-style pagination customize in template

I am using django-el-pagination package and trying to implement digg-style pagination on my home template. I am displaying it with..
{% get_pages %}
{{ pages.get_rendered }}
and it is showing like this <1234567> which is fine but
I want to add some css or class to change the way it look.
If you have any other way to achieve this. Please suggest..
please tell how can I customize it.
You can change it to make it looks something like this or like whatever you want:
Here is an example:
{% get_pages %}
<div class="pagination">
{% for page in pages %}
<li class="page-item">{{ page.number }}</li>
{% endfor %}
</div>
You can check the documentation here: https://django-el-pagination.readthedocs.io/en/latest/templatetags_reference.html#get-pages to check all the available options for get_pages

Jekyll Pagination Index not found

First off, I am using Jekyll 3.5.1
I have enabled Pagination in my Jekyll config and have added the following to my _config.yml file:
#pagination
paginate: 5
paginate_path: "blog/page:num"
In my root directory, I have created a folder called 'blog' with inside of it an 'index.html' file. Yet, when I try to serve the file I get the warning that pagination can not find an index.html file.
I have also tried to just use the index.html file under root, but that was unsuccesfull as well.
Here you can see the github repo in case that would be of any help.
I have tried to play with the paginate_path as well as with the index.html file. Any help would be appreciated!
The concrete error message is:
Pagination: Pagination is enabled, but I couldn't find an index.html page to use as the pagination template. Skipping pagination.
Any help would be greatly appreciated.
One cause of this error message: The Brackets Editor 'Beautifier' command doesn't recognize YAML code when it executes, so it sees the top YAML of your index.html file:
---
layout: default
title: Jekyll Title
---
... and transforms the 4 lines into one continuous line:
--- layout: default title: Jekyll Themes ---
Jekyll responds with the error message:
Pagination: Pagination is enabled, but I couldn't find an index.html page to use as the pagination template. Skipping pagination."
index.html must not be empty. The pagination template file (as referred by pagination_path should contain the code to generate each page with the list of posts, as docs suggests, create blog/index.html:
---
layout: default
title: My Blog
---
<!-- This loops through the paginated posts -->
{% for post in paginator.posts %}
<h1>{{ post.title }}</h1>
<p class="author">
<span class="date">{{ post.date }}</span>
</p>
<div class="content">
{{ post.content }}
</div>
{% endfor %}
<!-- Pagination links -->
<div class="pagination">
{% if paginator.previous_page %}
Previous
{% else %}
<span class="previous">Previous</span>
{% endif %}
<span class="page_number ">Page: {{ paginator.page }} of {{ paginator.total_pages }}</span>
{% if paginator.next_page %}
Next
{% else %}
<span class="next ">Next</span>
{% endif %}
</div>

Twig extend based on isxmlhttprequest

I'm using Twig with Silex and are having some trouble with extend within an if statement. Basically the page is being extended even tho, the request is not done by AJAX.
{% if app.request.isXmlHttpRequest == false %}
{% extends 'layout.html.twig' %}
{% endif %}
However this works. The button is only being showed when the request is AJAX based.
{% if app.request.isXmlHttpRequest %}
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
{% endif %}
Also possibly worth mentioning my code is enclosed in an {% block content %} tag.
Does anyone have experience with this issue? (Being able to extend only if isXmlHttpRequest is false)
Thanks in advance
Try this one:
{% extends app.request.isxmlhttprequest ? "" : "layout.html.twig" %}
Behind the courtains extends is a token parsed in a way that no conditions can be placed around it, the outcome will be what you got: your template is always extended.
I'm not sure how it'll work with the empty string, you may need to create a "layout-ajax.html.twig" file with no content but the block you want to override.

Resources