Import Django model class in Scrapy project
<p>I have a django project and a scrapy project</p>

<p>and I want to import django model from to scrapy project.</p>

<p>This is my spider:</p>

<pre><code>import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor

import sys
sys.path.append('/home/ubuntu/venv/dict')
from dmmactress.models import EnActress

class JpnNameSpider(scrapy.Spider):

name = jp_name
allowed_domains = ['enjoyjapan.co.kr']
rx = EnActress.objects.values_list('name', flat=True)
rxs = rx.reverse()
start_urls = ['http://enjoyjapan.co.kr/how_to_read_japanese_name.php?keyword=%s' % jp for jp in rxs]

def parse(self, response):
    for sel in response('//*[@id="contents"]/div/div[1]/div/div[1]'):
        item = JapanessItem()
        item['koname'] = sel.xpath('div[4]/div[1]()/text()').extract()
        item['jpname'] = sel.xpath('div[2]/div[1]()/text()').extract()
        yield item

    next_page = response.css('#contents &gt; div &gt; div:nth-child(4) &gt; div &gt; a::attr(href)').extract_first()
    if naxt_page is not None:
        next_page = response.urljoin(next_page)
        yield scrapy.Request(next_page, self.parse)
</code></pre>

<p>and I got error when I ran spider</p>

<pre><code>django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configure.
</code></pre>

<p>-- Can someone help me to see what I am doing wrong?</p>

<p>Thanks in advance!</p>

<p>You need to <a href="https://docs.djangoproject.com/en/1.10/ref/applications/#initialization-process" rel="nofollow">initialize Django </a> before using models outside the context of Django apps:</p>

<pre><code>import django 
django.setup()
</code></pre>

python django scrapy