2017-09-14 101 views
1

我試圖在pythinanywhere上使用Django在python上構建項目。 我對Django一點都不熟悉,所以任何暗示它都是值得歡迎的。ImportError:沒有名爲weather_Core_Engine.weather_DB_Handler的模塊

我創建了一個名爲profiles的Django應用程序,並且我創建了一些db模型。到現在爲止還挺好。

我正在使用sqlite3,我設法遷移數據庫並正確啓動我的項目。

我現在已經修改了文件models.py但在使用命令運行遷移: 「蟒蛇./manage.py makemigrations」 我有以下問題:

"$ 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

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:

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代碼工作正常,沒有導入問題。

如果在這裏需要的是項目樹:

├── 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 

任何暗示?

回答

1

您沒有__init__.py文件將weather_Core_Engine作爲模塊。

0

最後,我明白了爲什麼我的服務器正在編譯,但數據庫遷移失敗。

我使用錯誤的Python版本來啓動遷移。

迫使Python版本我設法正確遷移DB:

$ python3.5 manage.py makemigrations 

我想無論如何要感謝的人誰試圖幫助我:)

相關問題