I am using django-allauth in my django application and the challenge I am facing has to do with the styling of the email sent. When a user registers, a confirmation mail is sent to the person but the email is just rendered as plain text. how can one style the email template.
Styling can be done in the templates. Look in allauth/account/email_confirm.html and other template files in that location.
You will need to copy those files to your own template directory before editing.
Other email templates are there as well. Also look into the email subdirectory, which contains .txt files which are included by the templates.
Related
I have been reading this part of the django documentation : https://docs.djangoproject.com/en/3.0/topics/forms/media/#assets-as-a-static-definition
and this raised a question for me.
I think in order for the animations and actions js files to be used by the browser they have to be referenced in a script html tag.
As defining js assets in the form widget, like shown in the documentation, does not add any tag in the html template I do not understand how these files will be retrieved by the browser.
I'll answer this question in parts.
How are the files retrieved
Remember the STATICFILES_DIRS setting in your settings.py? My take will be that Django, while rendering your files through the form, will automatically append that in front of your file name and then include it in your template (more on the next part).
In other words, Django does this the same way how it handles static files in your templates, but you don't have to manually load the tags.
Does not add any tag
Have you ever noticed that, while you were working with forms, all you type are CharFields and whatever and Django automatically loads those into the body tag? I believe Django will automatically do that (which the keyword arguments can be processed differently than the rest of your form) but loads into the script tag.
Cookiecutter-django uses:
django-allauth (which needs to send registration confirmation emails)
django-anymail configured to use mailgun.
Things are mostly working. But I can't figure out why I'm only getting plain text emails instead of HTML emails. I do have html emails defined in templates/account.
I must be missing a configuration setting someplace. But it looks like just the presense of the .html files should be enough.
So how do I get django-allauth to send html emails?
The reason why you are only getting plain text email is because django-allauth package does not contain any HTML email templates by default.
This is mentioned on the official django-allauth documentation found at https://django-allauth.readthedocs.io/en/latest/advanced.html#sending-email:
The project does not contain any HTML email templates out of the box. When you do provide these yourself, note that both the text and HTML versions of the message are sent.
You need to follow the instructions listed here (https://django-allauth.readthedocs.io/en/latest/advanced.html#sending-email) for the exact file structure + naming convention you need to use in order to create your project specific HTML templates.
I have a file in my /private folder which I then use for SSR.compileTemplate and SSR.render to send nice html verification email; is it possible to style it with bootstrap as well? if so where I should put the real client-like template file ?
If its for email template you will need inline styles in order to make it work with most of the email services, so you just use a css inliner(like this one http://foundation.zurb.com/emails/inliner.html).
Another problem you might find is that some features don't work, like media queries, so its possible that your bootstrap styles don't look as you wanted.
I recommend you to use the zurb foundation emails, It has great compatibility with most of the email clients http://foundation.zurb.com/emails.html
I'm using basic Yii2 template. I downloaded login template from the Internet (there are .html and .css files). I'd like to connect it to the Yii2 framework to be shown this way - when I write the the address on Internet browser, this login template will be shown as first, after login of user will be shown the basic Yii2 template and after logout will be shown the login template again.
How can I do that and where and what should I to set? Where should I copy the two files of the login template?
To edit login template, you need to edit view files.
Since you're using basic yii2 application, you can go to /views/site/login.php file to edit login page template and copy html source. But make sure that you follow yii2 framework guideline while editing.
To add your own css, you can replace it on /web/css/site.css.
I'm writing a Django 1.4 app that will send HTML email. I'm using Django templates to render the email content, but I'm unsure how to store the templates.
I can store them in an email app (like I would other templates), but it feels silly to use a static file.
I thought about creating an Email model and storing the template code as a TextField, which would work.
I searched for better solutions and saw sendwithus.com on reddit, which is a neat idea...
Is there a Django convention for this sort of thing?
The general approach is to store email templates either globally in the project template folder or in the template folder of your email app. If you build a reusable app you can provide examples of email templates in your apps template folder, but make it possible to overwrite them via global project template (prioritize project templates before app templates in TEMPLATE_READERS, usually the default in django).
I think you other ideas are overkill for something so simple.