小编Raf*_*cho的帖子

无法删除Django中特定条目的缓存

我正在尝试使用信号保存一个特定条目的缓存.

我正在使用装饰器(signalsrender_to)django-annoying

@signals.post_save(sender=Artigo)
def artigo_post_save(instance, **kwargs):

    from django.http import HttpRequest
    from django.utils.cache import get_cache_key
    from django.core.cache import cache

    # cache.delete(instance.get_absolute_url()) # not work

    request = HttpRequest()
    request.method = "GET"
    request.path = '/' + instance.get_absolute_url()

    print 'request path: ', request.path

    key = get_cache_key(request=request, 
                        key_prefix=settings.CACHE_MIDDLEWARE_KEY_PREFIX)

    print "found key" if cache.has_key(key) else "notfound key"

    if cache.has_key(key):
        cache.delete(key)
        cache.set(key, None, 0)
Run Code Online (Sandbox Code Playgroud)
  • 问题是当我保存模型时,我得到输出"notfound key",因此缓存继续而不清除
  • request.path 适当地指向我的进入路径.

一些设置:

SESSION_ENGINE = "django.contrib.sessions.backends.cache"
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
CACHE_MIDDLEWARE_KEY_PREFIX = 'cache'
CACHE_MIDDLEWARE_SECONDS = …
Run Code Online (Sandbox Code Playgroud)

python django caching

13
推荐指数
1
解决办法
2115
查看次数

Scrapy如何使用Loader忽略带有空白字段的项目

我想知道如何忽略不填充所有字段的项目,某种丢弃,因为在scrapyd的输出中我得到的页面没有填满所有字段.

我有那个代码:

class Product(scrapy.Item):
    source_url = scrapy.Field(
        output_processor = TakeFirst()
    )
    name = scrapy.Field(
        input_processor = MapCompose(remove_entities),
        output_processor = TakeFirst()
    )
    initial_price = scrapy.Field(
        input_processor = MapCompose(remove_entities, clear_price),
        output_processor = TakeFirst()
    )
    main_image_url = scrapy.Field(
        output_processor = TakeFirst()
    )
Run Code Online (Sandbox Code Playgroud)

分析器:

def parse_page(self, response):
    try:
        l = ItemLoader(item=Product(), response=response)
        l.add_value('source_url', response.url)
        l.add_css('name', 'h1.title-product::text')
        l.add_css('main_image_url', 'div.pics a img.zoom::attr(src)')

        l.add_css('initial_price', 'ul.precos li.preco_normal::text')
        l.add_css('initial_price', 'ul.promocao li.preco_promocao::text')

        return l.load_item()

    except Exception as e:
        print self.log("#1 ERRO: %s" % e), response.url
Run Code Online (Sandbox Code Playgroud)

我想用Loader做它而不需要用我自己的Selector创建(避免两次处理项目).我想我可以将它们放到管道中,但可能不是最好的方法,因为这些项目无效.

python scrapy scrapyd

5
推荐指数
1
解决办法
1905
查看次数

PyQT分段错误(有时)

我正在创建一个界面来管理一些服务器,基本的功能,如重新启动服务,并认为这样,我进入界面QTCreator和编程PyQT5,它正常工作(有时).

有时它只是工作,有时我得到Segmentation FaultQObject::connect: Cannot queue arguments of type 'QTextCursor' (Make sure 'QTextCursor' is registered using qRegisterMetaType().)

它发生在我进入restart_nginxMainWindow,可能是线程管理的一些问题,这是我正在使用的第一个项目PyQT/QT

谢谢.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import paramiko
import threading

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from ui_mainwindow import Ui_MainWindow

servers = {
    "Mars": "198.58.112.***",
    "Saturn": "198.58.116.***"
}

green = "rgb(83, 236, 17)"
default = "rgb(154, 154, 154)"
yellow …
Run Code Online (Sandbox Code Playgroud)

python qt multithreading pyqt pyqt5

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

标签 统计

python ×3

caching ×1

django ×1

multithreading ×1

pyqt ×1

pyqt5 ×1

qt ×1

scrapy ×1

scrapyd ×1