ImportError:没有名为weather_Core_Engine.weather_DB_Handler的模块

时间:2017-09-14 16:31:01

标签: python django sqlite importerror pythonanywhere

我正在尝试在pythinanywhere上使用Django在python上构建一个项目。 我对Django一点都不熟悉所以任何提示都非常受欢迎。

我创建了一个名为profiles的Django应用程序,并在那里创建了一些数据库模型。到目前为止一切顺利。

我正在使用sqlite3,我设法迁移数据库并正确启动我的项目。

现在我修改了models.py文件,但在使用命令运行迁移时: “python ./manage.py makemigrations” 我有以下问题:

:

这是文件view.py

"$ python ./manage.py makemigrations Traceback (most recent call last):   File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)   File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()   File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)   File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 305, in run_from_argv
    self.execute(*args, **cmd_options)   File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 353, in execute
    self.check()   File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 385, in check
    include_deployment_checks=include_deployment_checks,   File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 372, in _run_checks
    return checks.run_checks(**kwargs)   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)   File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 310, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)   File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 303, in urlconf_module
    return import_module(self.urlconf_name)   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)   File "/home/Alexio/Mico_Weather_BackTrace/Mico_Weather_BackTrace/urls.py", line 21, in <module>
    from profiles import views   File "/home/Alexio/Mico_Weather_BackTrace/profiles/views.py", line 3, in <module>
    from profiles.weather_Core_Engine.weather_DB_Handler import DB_handler ImportError: No module named weather_Core_Engine.weather_DB_Handler" 

此处还修改了models.py:

from django.shortcuts import render

from profiles.weather_Core_Engine.weather_DB_Handler import DB_handler
from profiles.weather_Core_Engine.weather_Request_Handler import request_weather

import time
import datetime


# Create your views here.
def home(request):
    context = locals()
    template = 'home.html'
    return render(request,template,context)


def about(request):
    DB_handler.populate_db()
    # get input
    city = 'Asti'
    days = '2017/09/01'
    #s = "01/12/2011"
    days_to_time = time.mktime(datetime.datetime.strptime(days, "%Y/%m/%d").timetuple())
    print ("Hello ale before")
    #new_val = request_weather.history(city, days)
    new_val = request_weather.historyOpen(city, days)

    print ("Hello ale After")
    print (new_val)
    cities = DB_handler.get_cities()
    context = {
        'city_name':'about_Ale',
        'city_name_db':cities,
        'title':'News'
       #'city_name':'about'+  str(cities).encode('utf-8')
       #'city_name':'about'+  cities.strip().decode('utf-8')
    }
    template = 'about.html'
    return render(request,template,context)

我不了解迁移数据库时的导入问题。 服务器的python代码工作正常,没有导入问题。

如果需要,

是项目树:

from __future__ import unicode_literals
from django.db import models
import datetime

# Create your models here.
class profile(models.Model):
    name = models.CharField(max_length=120)
    description = models.TextField(default='description default text')
    def __unicode__(self):
        return self.name


class Cities(models.Model):
    id = models.IntegerField(primary_key=True)
    date = models.DateField(("Date"), default=datetime.date.today)
    city_name = models.CharField(max_length=2048)
    Json = models.TextField()

任何提示?

2 个答案:

答案 0 :(得分:1)

您没有__init__.py个文件来制作weather_Core_Engine模块。

答案 1 :(得分:0)

最后,我理解为什么我的服务器正在编译,但数据库迁移失败了。

我使用了错误的Python版本来启动迁移。

强制我设法正确迁移数据库的python版本:

$ python3.5 manage.py makemigrations 

无论如何,我要感谢任何试图帮助我的人:)