Max Iskram
Max Iskram

Reputation: 197

django openshift import views error

It's been impossible for me to make work any django "Hello World" example on openshift. I'm just trying to do the most basic example based on urls.py, views.py and wsgi.py. This is the structure

wsgi
-myproject
--myproject
---__init__.py
---settings.py
---urls.py
---views.py
---wsgi.py

and urls.py, where is the import views (with # you can see some trials)

from django.conf.urls import include, url
from django.contrib import admin
#from . import views
#import views
from myproject import views
urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^admin/', include(admin.site.urls)),
]

The thing is that I can't get out of the "ImportError - cannot import name views" situation. I've read lots of stackoverflow threads, tried lots of answers but nothing. Istead of importing, if I copy the views.py content into urls.py, it works ok.

Here the wsgi.py content, full of sys.path.append that I added trying to find a solution:

import os, sys
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR']))
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi'))
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'myproject'))
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'myproject'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python3.3/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

I created this project into the openshift web console, and modified it with liclipse (eclipse pydev). The thing has to do with openshift, I made some local examples and no problem at all.

PLEASE HELP - I'm really starting to think that openshift doesn't work with django, at least for beginners. Thanks

Upvotes: 1

Views: 101

Answers (1)

fips
fips

Reputation: 4379

Try using a relative import since your views is in the same dir as urls:

from . import views

And maybe read the python docs on how to use absolute/relative imports: https://docs.python.org/2.5/whatsnew/pep-328.html

Upvotes: 1

Related Questions