使用django项目和Scrapy的virtualenv

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用django项目和Scrapy的virtualenv相关的知识,希望对你有一定的参考价值。

  1. # This snippet is useful when you want to use a django project which runs in a Python virtual environment.
  2.  
  3. """
  4. This code should be executed before the imports you need from your django project
  5. For example, you can place it at the end of your settings.py
  6. """
  7.  
  8. import sys, os
  9.  
  10. # Add the directory containing your django project 'myproj' to the path
  11. sys.path.insert(0, '/django-projs/')
  12.  
  13. # Set the django settings environment variable
  14. os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings'
  15.  
  16. # Activate the virtual environment used in the django project
  17. execfile('/path/to/virtual/env/bin/activate_this.py',
  18. {'__file__': '/path/to/virtual/env/bin/activate_this.py'})
  19.  
  20. # Now you can import any model, for example
  21. from myproj.myapp.models import MyModel
  22.  
  23. # Snippet imported from snippets.scrapy.org (which no longer works)
  24. # author: anibal
  25. # date : Aug 16, 2010
  26.  

以上是关于使用django项目和Scrapy的virtualenv的主要内容,如果未能解决你的问题,请参考以下文章

Scrapy & Django项目

jdango+scrapy结合使用并爬取数据入库

初学Django

2018.2最新-Scrapy+elasticSearch+Django打造搜索引擎

InterfaceError:连接已关闭(使用 django + celery + Scrapy)

爬虫例子及知识点(scrapy知识点)