首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImportError:没有名为weather_Core_Engine.weather_DB_Handler的模块

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

Stack Overflow用户
提问于 2017-09-15 00:31:01
回答 2查看 250关注 0票数 1

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

我创建了一个名为profiles的Django应用程序,在那里我创建了一些db模型。到目前一切尚好。

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

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

代码语言:javascript
复制
"$ 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" 

这是文件view.py

代码语言:javascript
复制
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)

在这里它也是修改后的models.py:

代码语言:javascript
复制
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()

我不理解迁移数据库时的导入问题。服务器的python代码运行良好,没有导入问题。

如果需要,这里是项目树:

代码语言:javascript
复制
├── Mico_Weather_BackTrace
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── __pycache__
│   │   ├── __init__.cpython-35.pyc
│   │   ├── settings.cpython-35.pyc
│   │   └── urls.cpython-35.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   └── wsgi.py
├── apixu-python-master
│   ├── README.md
│   ├── apixu
│   │   ├── __init__.py
│   │   ├── client.py
│   │   └── tests
│   │       ├── current_tests.py
│   │       └── forecast_tests.py
│   └── setup.py
├── db.sqlite3
├── manage.py
├── media
├── profiles
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── __pycache__
│   │   ├── __init__.cpython-35.pyc
│   │   ├── admin.cpython-35.pyc
│   │   ├── models.cpython-35.pyc
│   │   ├── models.cpython-36.pyc
│   │   ├── views.cpython-35.pyc
│   │   └── weather_DB_Handler.cpython-35.pyc
│   ├── admin.py
│   ├── admin.pyc
│   ├── apps.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── 0001_initial.pyc
│   │   ├── 0002_profile_description.py
│   │   ├── 0002_profile_description.pyc
│   │   ├── 0003_cities.py
│   │   ├── 0003_cities.pyc
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── templates
│   │   ├── about.html
│   │   ├── base.html
│   │   └── home.html
│   ├── tests.py
│   ├── tests.pyc
│   ├── views.py
│   ├── views.pyc
│   └── weather_Core_Engine
│       ├── __pycache__
│       │   ├── weather_DB_Handler.cpython-35.pyc
│       │   └── weather_Request_Handler.cpython-35.pyc
│       ├── weather_CityRegstration_Handler.py
│       ├── weather_DB_Handler.py
│       ├── weather_Request_Handler.py
│       └── weather_Updater_Handler.py
└── static
    ├── admin
    │   ├── css
    │   │   ├── base.css
    │   │   ├── changelists.css
    │   │   ├── dashboard.css
    │   │   ├── fonts.css
    │   │   ├── forms.css
    │   │   ├── login.css
    │   │   ├── rtl.css
    │   │   └── widgets.css
    │   ├── fonts
    │   │   ├── LICENSE.txt
    │   │   ├── README.txt
    │   │   ├── Roboto-Bold-webfont.woff
    │   │   ├── Roboto-Light-webfont.woff
    │   │   └── Roboto-Regular-webfont.woff
    │   ├── img
    │   │   ├── LICENSE
    │   │   ├── README.txt
    │   │   ├── calendar-icons.svg
    │   │   ├── gis
    │   │   │   ├── move_vertex_off.svg
    │   │   │   └── move_vertex_on.svg
    │   │   ├── icon-addlink.svg
    │   │   ├── icon-alert.svg
    │   │   ├── icon-calendar.svg
    │   │   ├── icon-changelink.svg
    │   │   ├── icon-clock.svg
    │   │   ├── icon-deletelink.svg
    │   │   ├── icon-no.svg
    │   │   ├── icon-unknown-alt.svg
    │   │   ├── icon-unknown.svg
    │   │   ├── icon-yes.svg
    │   │   ├── inline-delete.svg
    │   │   ├── search.svg
    │   │   ├── selector-icons.svg
    │   │   ├── sorting-icons.svg
    │   │   ├── tooltag-add.svg
    │   │   └── tooltag-arrowright.svg
    │   └── js
    │       ├── SelectBox.js
    │       ├── SelectFilter2.js
    │       ├── actions.js
    │       ├── actions.min.js
    │       ├── admin
    │       │   ├── DateTimeShortcuts.js
    │       │   └── RelatedObjectLookups.js
    │       ├── calendar.js
    │       ├── cancel.js
    │       ├── change_form.js
    │       ├── collapse.js
    │       ├── collapse.min.js
    │       ├── core.js
    │       ├── inlines.js
    │       ├── inlines.min.js
    │       ├── jquery.init.js
    │       ├── popup_response.js
    │       ├── prepopulate.js
    │       ├── prepopulate.min.js
    │       ├── prepopulate_init.js
    │       ├── timeparse.js
    │       ├── urlify.js
    │       └── vendor
    │           ├── jquery
    │           │   ├── LICENSE-JQUERY.txt
    │           │   ├── jquery.js
    │           │   └── jquery.min.js
    │           └── xregexp
    │               ├── LICENSE-XREGEXP.txt
    │               ├── xregexp.js
    │               └── xregexp.min.js
    ├── media
    ├── static
    │   └── css
    │       ├── font-awesome.min.css
    │       ├── main.css
    │       ├── roboto.css
    │       ├── w3-theme-black.css
    │       └── w3.css
    └── static-only
        ├── admin
        │   ├── css
        │   │   ├── base.css
        │   │   ├── changelists.css
        │   │   ├── dashboard.css
        │   │   ├── fonts.css
        │   │   ├── forms.css
        │   │   ├── login.css
        │   │   ├── rtl.css
        │   │   └── widgets.css
        │   ├── fonts
        │   │   ├── LICENSE.txt
        │   │   ├── README.txt
        │   │   ├── Roboto-Bold-webfont.woff
        │   │   ├── Roboto-Light-webfont.woff
        │   │   └── Roboto-Regular-webfont.woff
        │   ├── img
        │   │   ├── LICENSE
        │   │   ├── README.txt
        │   │   ├── calendar-icons.svg
        │   │   ├── gis
        │   │   │   ├── move_vertex_off.svg
        │   │   │   └── move_vertex_on.svg
        │   │   ├── icon-addlink.svg
        │   │   ├── icon-alert.svg
        │   │   ├── icon-calendar.svg
        │   │   ├── icon-changelink.svg
        │   │   ├── icon-clock.svg
        │   │   ├── icon-deletelink.svg
        │   │   ├── icon-no.svg
        │   │   ├── icon-unknown-alt.svg
        │   │   ├── icon-unknown.svg
        │   │   ├── icon-yes.svg
        │   │   ├── inline-delete.svg
        │   │   ├── search.svg
        │   │   ├── selector-icons.svg
        │   │   ├── sorting-icons.svg
        │   │   ├── tooltag-add.svg
        │   │   └── tooltag-arrowright.svg
        │   └── js
        │       ├── SelectBox.js
        │       ├── SelectFilter2.js
        │       ├── actions.js
        │       ├── actions.min.js
        │       ├── admin
        │       │   ├── DateTimeShortcuts.js
        │       │   └── RelatedObjectLookups.js
        │       ├── calendar.js
        │       ├── cancel.js
        │       ├── change_form.js
        │       ├── collapse.js
        │       ├── collapse.min.js
        │       ├── core.js
        │       ├── inlines.js
        │       ├── inlines.min.js
        │       ├── jquery.init.js
        │       ├── popup_response.js
        │       ├── prepopulate.js
        │       ├── prepopulate.min.js
        │       ├── prepopulate_init.js
        │       ├── timeparse.js
        │       ├── urlify.js
        │       └── vendor
        │           ├── jquery
        │           │   ├── LICENSE-JQUERY.txt
        │           │   ├── jquery.js
        │           │   └── jquery.min.js
        │           └── xregexp
        │               ├── LICENSE-XREGEXP.txt
        │               ├── xregexp.js
        │               └── xregexp.min.js
        └── css
            ├── font-awesome.min.css
            ├── main.css
            ├── roboto.css
            ├── w3-theme-black.css
            └── w3.css

有什么提示吗?

EN

回答 2

Stack Overflow用户

发布于 2017-09-19 01:42:50

您没有使weather_Core_Engine成为模块的__init__.py文件。

票数 1
EN

Stack Overflow用户

发布于 2017-09-26 01:59:01

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

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

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

代码语言:javascript
复制
$ python3.5 manage.py makemigrations 

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46224229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档