如何在网站中发布外部url

2024-09-25 10:27:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在学习django和web编程。 我想做一个实践网站,显示另一个网站的搜索结果。我使用$requests$获取页面,$Httpresponse$显示页面结果,但结果页面不显示表和图像。 当我用浏览器打开html时

我不想使用iframe,因为页面上有一个按钮我不想出现在我的页面中

def index(request):
    ...
    if request.method == 'POST':  # If the form has been submitted...
         html=requests.get(url).text
          return HttpResponse(html)

Failed to load resource: the server responded with a status of 404 (Not Found) info-small.png:1

Failed to load resource: the server responded with a status of 404 (Not Found) (index):63 Uncaught

ReferenceError: $ is not defined at (index):63 warning-32.png:1 Failed to load resource: the server responded with a status of 404 (Not Found) (index):2134

Uncaught ReferenceError: $ is not defined at (index):2134 info-small.png:1 Failed to load resource: the server responded with a status of 404 (Not Found)


Tags: ofthetoindexserverhtmlstatuswith
1条回答
网友
1楼 · 发布于 2024-09-25 10:27:11

如果您从自己的网站提供另一个网站的HTML代码,这将打破对图像、样式表、脚本等的本地引用。你知道吗

例如,如果页面http://example.com/index.htm包含代码

<img src="/img/logo.png" />

这是指http://example.com/img/logo.png。如果您包含相同的代码,但在您自己的网站http://my.website/page.htm下提供它,则浏览器会将其理解为指向http://my.website/img/logo.png,而http://my.website/img/logo.png并不存在。你知道吗

因此,如果您想为另一个网站的HTML内容提供服务,则需要调整所有本地路径以引用正确的资源(通过自己提供服务或指向原始的绝对URI)。你可能会遇到其他问题,所以除非你有充分的理由走这条路,否则我不建议你这么做。你知道吗

相关问题 更多 >