小编Alf*_*wan的帖子

在 FLASK 中使用 ajax 发布数据后如何渲染模板?

我有一个问题,我无法在使用 ajax 发布数据后打开 render_template。这是我的 ajax 代码。

if ($(this).attr("value") == "button-three") {

    var skoring = getRadioVal(document.getElementById('mentodeNegasi'),'negasi')

    $.ajax({
        data: { metodeSkoring: skoring },
        type: 'POST',
        url: '/evaluasiModel'
    })
}
Run Code Online (Sandbox Code Playgroud)

这是我的服务器代码。

@app.route('/evaluasiModel', methods=['POST',"GET"])              
def evaluasiModel():
    metodeSkoring = request.form['metodeSkoring']
    metodeSkoring = int(metodeSkoring)
    return render_template("evaluasiModelKlasifikasi.html", hasilSkoring = metodeSkoring)
Run Code Online (Sandbox Code Playgroud)

我希望在将数据ajax发布到“def evaluasiModel()”后,我可以打开render_template“evaluasiModelKlasifikasi.html”并获取数据metodeSkoring以显示在此模板中。

javascript python ajax jquery flask

4
推荐指数
1
解决办法
8768
查看次数

TypeError:'float'对象不可迭代我正在使用scrapy和python 3.5

我的scrapyspider有问题,它使用以下代码:

class MySpider(BaseSpider):
    name = "craig"
    allowed_domains = ["craigslist.org"]
    start_urls = ["http://sfbay.craigslist.org/search/npo"]

    def parse(self, response):
    hxs = HtmlXPathSelector(response)
    titles = hxs.xpath("//span[@class='pl']")
    items = []
    for i in titles:
        item = CraigslistSampleItem()
        item["title"] = i.select("a/text()").extract()
        item["link"] = i.select("a/@href").extract()
        items.append(item)
    return items
Run Code Online (Sandbox Code Playgroud)

这是我的 items.py

from scrapy.item import Item, Field

class CraigslistSampleItem(Item):
    title = Field()
    link = Field()
Run Code Online (Sandbox Code Playgroud)

当我运行蜘蛛时scrapy crawl craig,我收到以下错误:

TypeError: 'float' object is not iterable
2017-03-07 10:13:44 [scrapy.core.scraper] ERROR: Error downloading <GET http://sfbay.craigslist.org/search/npo>
TypeError: 'float' object is not iterable …
Run Code Online (Sandbox Code Playgroud)

python scrapy

2
推荐指数
1
解决办法
1053
查看次数

标签 统计

python ×2

ajax ×1

flask ×1

javascript ×1

jquery ×1

scrapy ×1