python - 输出未显示在 django 框架中
问题描述
下面是我的代码!我想在 html 中运行 python 脚本,但是每次执行时我都看不到输出!请帮忙!下面是我的代码!我想在 html 中运行 python 脚本,但是每次执行时我都看不到输出!请帮忙!下面是我的代码!我想在 html 中运行 python 脚本,但是每次执行时我都看不到输出!请帮忙!下面是我的代码!我想在 html 中运行 python 脚本,但是每次执行时我都看不到输出!请帮忙!
views.py
from django.shortcuts import render
import requests
def button(request):
return render(request,'home.html')
def output(request):
data=requests.get('https://www.google.com/')
print(data.text)
data=data.text
return render(request,'home.html',{'data':data})
urls.py
from django.contrib import admin
from django.conf.urls import url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'admin/', admin.site.urls),
url(r'^$', views.button),
url(r'^$', views.output, name="script")
]
home.html
</!DOCTYPE html>
<html>
<head>
<title>Python Script</title>
</head>
<body>
<button onclick="location.href='{% url 'script' %}'">Click Me</button>
<hr>
{% if data %}
{{data | safe}
{% endif %}
</body>
</html>
解决方案
推荐阅读
- python - Pandas 数据框条件均值
- ldap - ldapadd / ldapmodify - 添加数据库参数
- talend - 在 TALEND open studio 中转换日期时出错
- c++ - 不能将结构传递给另一个文件中声明的函数?
- mongodb - 连接多个集合、组、排序推送数组并重组结果的 MongoDB 查询
- python - 从 python 程序导出数据我做错了什么?
- php - AMPHP 抛出无法捕获的 MultiReasonException - 这是一个错误吗?
- java - Connect 4 check win方法抛出索引越界错误
- python - 在 Python 中使用堆的前 K 个常用词
- twilio - 收集后针对多个 Twilio 类型和自定义字段类型检查 Twilio 自动驾驶仪用户输入