[英]Django can't import taggit module in apache server, fine in local server, Import from manage.py shell but django can't import it, No virtualenv used
[英]Can't import local module inside script, like I do in Django shell
這是錯誤:
Traceback (most recent call last):
File "twitterstream.py", line 3, in <module>
from tweemo.models import TwitterStream
ImportError: No module named tweemo.models
背景:
在Django中,我有一個簡單的模型,看起來像這樣:
from django.db import models
class TwitterStream(models.Model):
text = models.CharField()
在Django Shell中,我可以毫無問題地執行以下操作
>>> from tweemo.models import TwitterStream
>>> tweet = TwitterStream.objects.create(text = 'hello again')
>>> tweet.text
'hello again'
因為這在django shell中有效,所以我認為我可以插入以下行:
>>> from tweemo.models import TwitterStream
插入任何常規的python腳本中,例如,將數據插入腳本中的TwitterStream Model(因此將其插入我的Mondo數據庫)形式。
基本上,我有一個腳本,可以將twitter實時流打印到命令行上。 試圖通過包含此內容對其進行修改
>>> from tweemo.models import TwitterStream
並更改此:
for line in response:
print response
到這個:
for line in response:
tweet = str(tweet) + str(" ") + str(count)
tweet = TwitterStream.objects.create(text = line.strip())
count += 1
僅供參考:包含TwitterStream類的我的models.py位於我的應用程序“ tweemo”中,該應用程序位於一個項目(也稱為“ twitter”)中。 我想用來將實時流發送到mymongo DB的python腳本與models.py文件-tweemo應用程序文件夾位於同一文件夾中。
我是Django / Mongo的新手,所以這里距離我很遠。
提前致謝
如果通過Django Shell導入模型,則必須通過項目文件夾中的py文件進行導入。 我唯一的猜測是刪除項目文件夾中的pyc文件並進行測試。如果沒有,@dannymilsom解決方案將派上用場:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.