Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Added from_crawler to middleware docs

Jesse Bakker0b14cb44aabc
diff --git a/docs/topics/downloader-middleware.rst b/docs/topics/downloader-middleware.rst
index 0d168017f..983a93290 100644
--- a/docs/topics/downloader-middleware.rst
+++ b/docs/topics/downloader-middleware.rst
@@ -157,6 +157,17 @@ more of the following methods:
:param spider: the spider for which this request is intended
:type spider: :class:`~scrapy.spiders.Spider` object
+ .. method:: from_crawler(cls, crawler)
+
+ If present, this classmethod is called to create a middleware instance
+ from a :class:`~scrapy.crawler.Crawler`. It must return a new instance
+ of the middleware. Crawler object provides access to all Scrapy core
+ components like settings and signals; it is a way for middleware to
+ access them and hook its functionality into Scrapy.
+
+ :param crawler: crawler that uses this middleware
+ :type crawler: :class:`~scrapy.crawler.Crawler` object
+
.. _topics-downloader-middleware-ref:
Built-in downloader middleware reference
diff --git a/docs/topics/spider-middleware.rst b/docs/topics/spider-middleware.rst
index a2d2556c5..c297ed556 100644
--- a/docs/topics/spider-middleware.rst
+++ b/docs/topics/spider-middleware.rst
@@ -164,6 +164,17 @@ following methods:
:param spider: the spider to whom the start requests belong
:type spider: :class:`~scrapy.spiders.Spider` object
+ .. method:: from_crawler(cls, crawler)
+
+ If present, this classmethod is called to create a middleware instance
+ from a :class:`~scrapy.crawler.Crawler`. It must return a new instance
+ of the middleware. Crawler object provides access to all Scrapy core
+ components like settings and signals; it is a way for middleware to
+ access them and hook its functionality into Scrapy.
+
+ :param crawler: crawler that uses this middleware
+ :type crawler: :class:`~scrapy.crawler.Crawler` object
+
.. _Exception: https://docs.python.org/2/library/exceptions.html#exceptions.Exception