使用django项目和Scrapy的virtualenv
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用django项目和Scrapy的virtualenv相关的知识,希望对你有一定的参考价值。
# This snippet is useful when you want to use a django project which runs in a Python virtual environment. """ This code should be executed before the imports you need from your django project For example, you can place it at the end of your settings.py """ import sys, os # Add the directory containing your django project 'myproj' to the path sys.path.insert(0, '/django-projs/') # Set the django settings environment variable os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings' # Activate the virtual environment used in the django project execfile('/path/to/virtual/env/bin/activate_this.py', {'__file__': '/path/to/virtual/env/bin/activate_this.py'}) # Now you can import any model, for example from myproj.myapp.models import MyModel # Snippet imported from snippets.scrapy.org (which no longer works) # author: anibal # date : Aug 16, 2010
以上是关于使用django项目和Scrapy的virtualenv的主要内容,如果未能解决你的问题,请参考以下文章
2018.2最新-Scrapy+elasticSearch+Django打造搜索引擎