Q
Q
Quattro1112020-06-02 14:20:26
Django
Quattro111, 2020-06-02 14:20:26

Working with forms in Django to create posts, how to insert a link inside a post?

I started learning django, writing a website with a blog (purely for practice)
I made a form for creating a post:

class PostForm(forms.ModelForm):
    class Meta:
        model = Rost
        fields = ['title', 'slug', 'body', 'tags']

        widgets = {
            'title':forms.TextInput(attrs={'class':'form-control'}),
            'slug':forms.TextInput(attrs={'class':'form-control'}),
            'body': forms.Textarea(attrs={'class':'form-control'}),
            'tags':forms.SelectMultiple(attrs={'class':'form-control'}),
            }


How to make a form sensitive to HTML code? Let me explain. Let's say I'm writing text in the post body field and I want to insert a link there: link
How can I make my tags be converted to page code when the created post is displayed? (at the moment the post is displayed along with all the tags that contain the words)
Are there other ways to make links inside the post?
Thank you in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
milssky, 2020-06-02
@milssky

Something like this in the template.
https://docs.djangoproject.com/en/3.0/ref/template...

D
Dmitry, 2020-06-11
@pyHammer

{{ object.body|raw }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question