使用块内容将数据发送到HTML页

2024-09-21 01:11:34 发布

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

我用pythondjango编写了代码来解析url并将标记数据发送到另一个html页面,所以我已经编写了代码视图.py我需要使用块内容将数据发送到html页面。在

代码:

在视图.py在

from django.shortcuts import render_to_response
import urllib  
import re 

def home(request):
    htmlf = urllib.urlopen("https://docs.djangoproject.com/en/dev/topics/http/urls") 
    htmlt = htmlf.read() 
    regex = '<title>(.+?)</title> ' 
    patt = re.compile(regex) 
    price = re.findall(patt,htmlt) 
    return render_to_response("home.html", {'hello': price} )

在主页.html在

^{pr2}$

这里的问题是我需要在主页.html第页。在


Tags: to数据代码pyimportre视图home
1条回答
网友
1楼 · 发布于 2024-09-21 01:11:34

我想您使用的是django1.4+摆脱longrender_to_response

from django.shortcuts import render

def home(request):
    htmlf = urllib.urlopen("https://docs.djangoproject.com/en/dev/topics/http/urls") 
    htmlt = htmlf.read() 
    regex = '<title>(.+?)</title> ' 
    patt = re.compile(regex) 
    price = re.findall(patt,htmlt) 
    return render(request, "home.html", {'hello': price} )

相关问题 更多 >

    热门问题