小编Ton*_*ang的帖子

Gatsby gatsby-remark-relative-images不会将yaml绝对图像路径转换为相对

我目前正在尝试将yaml文件中的绝对路径解析为相对路径,以便可以在gatsby中使用graphql进行查询。绝对路径是从netlify-cms提供的。

当将相同的路径放置在md文件中并用于gatsby-remark-relative-images将其转换为相对路径时,它完全没有问题,但是相同的内容不适用于yaml。

将图像文件放入其中,static/img/cms提供的路径为/img/xxx.jpg

src / data / pages / index.yaml

page: index
slider:
  - image: /img/1_new.jpg
    url: ""
  - image: /img/2_new.jpg
    url: ""
  - image: /img/3_new.jpg
    url: ""
Run Code Online (Sandbox Code Playgroud)

gatsby-config.js

module.exports = {
  // ...
  plugins: [
    // ...
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/src/data`,
        name: 'data',
      },
    },
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        path: `${__dirname}/static/img`,
        name: 'uploads',
      },
    },
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        path: `${__dirname}/src/pages`,
        name: 'pages',
      },
    },
    {
      resolve: 'gatsby-source-filesystem',
      options: …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs gatsby netlify-cms

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

Scrapy自定义DownloadMiddleware不尊重DOWNLOAD_DELAY

我目前正在开发我的 CustomDownloadMiddleware。这主要是由于对网页下载有一定的控制需求。我的 CustomDownloadMiddleware 如下所示

class MySeleniumDownloadMiddleware:
    """Scrapy middleware handling the requests using selenium"""

    def __init__(self, driver):
        self.driver = driver
        self.cookies = self.driver.get_cookies()

    @classmethod
    def from_crawler(cls, crawler):
        """Initialize the middleware with the crawler settings"""

        driver = init_chromium(crawler.settings.get('SELENIUM_HOSTNAME'))
        login(driver, crawler.settings.get('MY_CREDENTIAL'))

        middleware = cls(driver=driver)

        crawler.signals.connect(middleware.spider_closed, signals.spider_closed)

        return middleware


    def process_request(self, request, spider):
        """Process a request using the selenium driver if applicable"""

        try:
            self.driver.get(request.url)
        except WebDriverException:
            self.driver = init_chromium(spider.settings.get('SELENIUM_HOSTNAME'))
            recover_cookie_to_driver(self.driver, self.cookies)
            self.driver.get(request.url)

        body = str.encode(self.driver.page_source)

        # Expose the driver via the "meta" attribute
        request.meta.update({'driver': …
Run Code Online (Sandbox Code Playgroud)

python scrapy

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

flask_restplus add_namespace 一直没有属性“as_view”

我编写了一个烧瓶,尝试按照本教程使用带有命名空间的蓝图来组织它

我遇到了一些问题,并环顾了互联网并在12 中查看了解决方案。第一个与我的工作无关,第二个解决方案无法解决我的问题。

这是我的代码:

项目/项目.py

from flask import Flask, jsonify, url_for
from .apis.apis import api

app = Flask(__name__)

app.register_blueprint(api, url_prefix="/api")
Run Code Online (Sandbox Code Playgroud)

项目/apis/apis.py

from flask import Blueprint
from .user.authentication import auth
from flask_restplus import Api, apidoc, Resource

blueprint = Blueprint("api", __name__)

api = Api(blueprint, doc='/docs', ui=False)

api.add_namespace(auth, path="/auth") #Keep getting error at this line
Run Code Online (Sandbox Code Playgroud)

项目/apis/用户/authentication.py

from flask_restplus import Namespace

auth = Namespace('auth', description='Authentication')

@auth.route("/test")
def authentication():
    return "test"
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪

    Traceback (most recent call last):
        File "/home/gaara/Python/Flask-Api/project/__init__.py", …
Run Code Online (Sandbox Code Playgroud)

python flask

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

标签 统计

python ×2

flask ×1

gatsby ×1

javascript ×1

netlify-cms ×1

reactjs ×1

scrapy ×1