0

So I was making this Django website and it does just what I want. But now I need to output the HTML code with indentation to an HTML page. I have used bs4 `s .prettify() method but it only shows the indented code on the console. This is my views.py main function

from django.shortcuts import render
import requests
from bs4 import BeautifulSoup as soup
from . forms import InForm


def main(request):
    if request.method == 'POST':
        form = InForm(request.POST)
        if form.is_valid():
            you = form.cleaned_data.get('you')
            htm = requests.get(you)
            dat = soup(htm.content, 'html.parser').prettify()
            print(dat)
            return render(request, 'main.html', {'dat':dat})
    else:
        form = InForm()
    return render(request, 'main.html', {'form':form})

the output I get:

enter image description here

I`m using an android emulator for the project

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41

1 Answers1

0

For indentation purpose you need css help

style.css

.article{
white-space: pre-line;
} 

main.html

<div class="article">
{{dat}}
</div>
Dharman
  • 30,962
  • 25
  • 85
  • 135
zak
  • 50
  • 5