Python + WSGI - не можете импортировать мои собственные модули из каталога?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Python + WSGI - не можете импортировать мои собственные модули из каталога?

Сообщение Anonymous »

Я новичок в Python, и я посмотрел на себя, как импортировать мои пользовательские модули из каталога/ под каталогов. Например, это и это. < /P>

Это моя структура, < /p>

index.py
__init__.py
modules/
hello.py
HelloWorld.py
moduletest.py
< /code>

index.py,

# IMPORTS MODULES
import hello
import HelloWorld
import moduletest

# This is our application object. It could have any name,
# except when using mod_wsgi where it must be "application"
def application(environ, start_response):

# build the response body possibly using the environ dictionary
response_body = 'The request method was %s' % environ['REQUEST_METHOD']

# HTTP response code and message
status = '200 OK'

# These are HTTP headers expected by the client.
# They must be wrapped as a list of tupled pairs:
# [(Header name, Header value)].
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', str(len(response_body)))]

# Send them to the server using the supplied function
start_response(status, response_headers)

# Return the response body.
# Notice it is wrapped in a list although it could be any iterable.
return [response_body]
< /code>

init.py, < /p>

from modules import moduletest
from modules import hello
from modules import HelloWorld
< /code>

modules/hello.py,

def hello():
return 'Hello World from hello.py!'
< /code>

modules/helloworld.py,

# define a class
class HelloWorld:
def __init__(self):
self.message = 'Hello World from HelloWorld.py!'

def sayHello(self):
return self.message
< /code>

modules/moduletest.py,

# Define some variables:
numberone = 1
ageofqueen = 78

# define some functions
def printhello():
print "hello"

def timesfour(input):
print input * 4

# define a class
class Piano:
def __init__(self):
self.type = raw_input("What type of piano? ")
self.height = raw_input("What height (in feet)? ")
self.price = raw_input("How much did it cost? ")
self.age = raw_input("How old is it (in years)? ")

def printdetails(self):
print "This piano is a/an " + self.height + " foot",
print self.type, "piano, " + self.age, "years old and costing\
" + self.price + " dollars."
< /code>

Но через Apache WSGI я получаю эту ошибку, < /p>


[wsgi: ошибка] [Pid 5840: Tid 828] [клиент 127.0.1:54621] импорт
hello [wsgi. 828] [Client 127.0.0.1:54621%
Importerror: Нет модуля с именем hello < /p>
< /blockquote>

Любая идея, что я сделал неправильно?index.py
__init__.py
modules/
hello.py
HelloWorld.py
moduletest.py
User/
Users.py


Подробнее здесь: https://stackoverflow.com/questions/320 ... -directory
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»