Django Userena Customization - django

I have recently installed Django Userena on my Linux Apache server.
After correcting some errors, I began looking through the documentation. However, after searching through the docs and after many Google searches, I still cannot find out how to change the appearance of the pages! For example, how do I change the appearance of the signin page, the signup page, etc? I know that each userena template extends base.html, but where do I go from there?
I am probably missing something very simple, so please forgive me if the answer is very obvious.

This is the signin method signature for Userena(source) -
def signin(request, auth_form=AuthenticationForm,
template_name='userena/signin_form.html',
redirect_field_name=REDIRECT_FIELD_NAME,
redirect_signin_function=signin_redirect, extra_context=None):
As you can see, there is a template_name method that holds the template location. You can override this. In your urls.py, you can use it like -
url(r'^signin/', 'userena.views.signin', {'template_name': 'signin.html'}, name="signin"),
You can then create the signin.html page inside your templates folder and extend base.html. The signin view sends the login form in a variable called form. You can see the source. You can use the form on your template signin.html like {{ form.as_p }}. You can also format each field individually if you can follow the userena.forms. AuthenticationForm. Again, check the source code. You can do the same for any view Userena has that allows overriding like this.
When in doubt, read the source code. :)

You need to override userena default templates.
Create a directory inside your templates/ named userena/, Then for example if you want to change signup form, easily create signup_form.html template file inside that userena/ dir that you've just created and start writing.
For instance here is default signup_form.html template.
You can find userena default templates at its github repo

Just copy the supplied userena templates in your template directory.
You can find them on a linux box with find / -name userena
The path you are looking for is ../userena/templates/userena. Copy the userena folder into your template directory and start changing the signin_form.html.

Just copy the templates to your own template directory. If you follow this link download and just copy the directory 'userena' to your template directory. You can then customise the templates including the email text and templates.

Related

Use the modified admin template only for one Image app

Django 3.0.6
For one model I need a modified admin site template.
Namely, I want to modify this template:
admin/includes/fieldset.html
I have copied the fieldset.html from Django package directory and placed it like this:
/my_project/image/templates/admin/includes/fieldset.html
Here image is my application. It is this application that needs a modified admin template.
The problem is that all other models also get this template. And the used template filters don't receive necessary params and explode.
Documentation: https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#set-up-your-projects-admin-template-directories
Well, I got confused and fail to organize the necessary directories structure.
How can I use the modified template only for one Image app?
You have a couple of issues. Firstly, only the following templates can be overridden per-app or per-model:
actions.html
app_index.html
change_form.html
change_form_object_tools.html
change_list.html
change_list_object_tools.html
change_list_results.html
date_hierarchy.html
delete_confirmation.html
object_history.html
pagination.html
popup_response.html
prepopulated_fields_js.html
search_form.html
submit_line.html
fieldset.html isn't in there, so you'll need to see if the including template(s) is in this list, and if it is, replace this template and use it to include your own version of fieldset.html.
Also, your location (slightly modified since can't override included templates per-app): /my_project/image/templates/admin/template.html isn't quite right. This will overwrite that template for every app. To do it per-app, you need a further subdirectory under admin:
/my_project/image/templates/admin/image/template.html
The reason for this is that templates don't really care about which app they're in, so the fact that the template lives in your image app doesn't mean anything to Django, the convention of putting them in your app's sub-directory is solely to avoid overriding templates that you don't intend to.

Override admin fieldset for model in app

Django admin docs state that you can override templates for specific models in specific apps by putting template in my_app/my_model subdirectory of templates/admin folder in your application.
I'm trying to override includes/fieldset.html template for my_model in my_app. Saving it as my_app/admin/my_app/my_model/includes/fieldset.html doesn't seem to work, while my_app/admin/includes/fieldset.html does, but overrides template for all pages in admin site.
Is there any way to achieve this behaviour?
Yes, the behavior is correct because not every template is getting override using this method per app or model, please read this.
allowed templates are :
app_index.html
change_form.html
change_list.html
delete_confirmation.html
object_history.html
popup_response.html
So what I had done is override all these per app and model or added in admin.py class change_form_template = 'admin/appname/customtemplate.html' this will give you full control over templates. You can / need also to change all inner templates using inner includes.

Implementing themes in Django (Custom templates by users)

I want to implement the feature for admins to set custom templates. Like they can place themes or templates in a particular folder relative to the home folder.
Each theme may have a folder and some config or preview for example(optional).
1) First I need to figure out how to set custom templates dir for an app.
2) Then I can probably do listdir and get all the folders and then give the admin an option to select the dir.
3) A setting list to specify additonal template folders by users.
1 is the problem.
The main question I want answer for is how to set custom template dir which can be modified anytime.
I found out that askbot (the SO clone) implements this kinda theming where you can place themes in subfolders a folder and the admin can select the folder which he/she wants the templates.
I am new to Django. I guess you can do it using jinja templating.
http://jinja.pocoo.org/
Add a common styling to one html page(base.html)
and then extend the base html to whichever pages u want using extends-- check out template inheritance in the above link
Also you can get some cool templates in bootstrap.. checkout their template section. https://www.w3schools.com/bootstrap/bootstrap_templates.asp
Good luck!

django: how to add home link to admin

I would like to add a link to / to every page in template. Can I do it without changing django internal template? I could customize django, but this is something I seriously wouldn't like to do.
Sure, just override one of the Django admin templates in your own templates/admin directory. For instance, copy the contents of django/contrib/admin/templates/base.html into yourproject/templates/admin/base.html. Then, change the latter to your heart's content.
See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates
According to the accepted answer, I still failed to make it. After some try-error experiments, my answer is:
copy django/contrib/admin/templates/base_site.html to as your_project/templates/admin/base_site.html
customize your local base_site.html to whatever you want
add to your settings.py
TEMPLATE_DIRS = ('templates',)

Django custom admin login template - form doesn't load, no input tags

I'm trying to make my own custom admin login template, so I just moved the login.html template to /templates/admin. The template loads, but there are input boxes. It's as if the form isn't being passed to this template file now and I have no idea why. The same code works on my development server, but when I put it on an actual server, the form just doesn't load. Am I missing a setting or something?
It could happen for a lot of reasons.
Make sure your TEMPLATE_DIRS is set properly. - Well since you said it is loading, I bet it is set but wont hurt to double check.
Make sure the blocks that display content are correct. - Of course, parts of the pages will fail to display if you have, say a mistyped or missing block. For easy reference, here is the code for login.html in the admin and the base_site.html that it extends.
If you are using a custom view, make sure to give the correct template path. - If your template root directory is in /templates, you should render the page in 'admin/login.html'.
Just a bit of advice, do a FORM HERE >> {{ form }} somewhere in your template to check if it actually has a value. Works for me.
As stated in my comment below i experienced the same issue, upgrading Django to the newest version in my server ( 1.3.1 ) fixed this issue.