Answer the question
In order to leave comments, you need to log in
How to display a link to another site using django?
What are the tools to display another site to the user?
Let's say a user visits my django site, enters a link to another site, and my site displays it in the browser window.
Works with simple sites.
from django.shortcuts import render
from urllib.request import urlopen
def website_index(request):
title = 'Another website viewer'
link = 'youtube.com'
if 'http' not in link:
link = 'http://' + link
html_code = str(urlopen(link).read(),'utf-8')
context = {
'title': title,
'html_code': html_code,
}
return render(request, 'my_app/index.html', context)
# потом в index.html
# {{ html_code|safe }}
# топорное решение
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question