0

I'm sending a message with HTML via Python. Now, I'd like to style it, I've tried to write the style code into the html but there are problems because curling braces {}. Can I link the css file in Python?

 <!DOCTYPE html>
 <html lang="en">
     <head>  
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
            <link href="https://fonts.googleapis.com/css?family=Lato:400,900i&display=swap" rel="stylesheet"> 
         <link rel='stylesheet' href="css/message_style.css"> #I've a static folder
     </head>
     <body>

1 Answer 1

1

You can do both inline stylings and also insert your CSS files into your HTML from a static folder like this:

{% load static from staticfiles %} or {% load static %}
<link rel='stylesheet' href="{% static 'css/message_style.css' %}">

Note: You should load static directory before using {% static 'relative address to the file' %}, and both {% load static from staticfiles %} or {% load static %} will do the same for you but the first one is more explicit.

EDIT: If you want to send out emails and make an email template you should use inline styles and use tables, to achieve that you can check this link for more information.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm sending this via email from a sever. When I use {% static ' ... ' %} it throw me the error: '''invalid syntax (<fstring>, line 1'''
@VicenteC Usually in emails we use inline styles, I will share some useful sources with you in the edited post.
You have to call {% load static %} before calling the style sheet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.