jfmatth / openshift-django17

Running django 1.7 apps on Red Hat's Openshift 2 DEPRECATED
MIT License
72 stars 25 forks source link

TemplateDoesNotExist at /index/ #8

Closed kc1 closed 9 years ago

kc1 commented 9 years ago

Hi again,

As you suggested I followed your directions to the letter and got your project working both locally and on openshift. Now I'm trying to make some changes to add my app. I've made minimal changes since getting it working. I've changed:

urlpatterns = patterns('',

url(r'^index/', 'app1.views.index', name='index'),

# url(r'^$', Index.as_view(), name='index'),

url(r'^admin/', include(admin.site.urls)),

)

and inserted the static files into the static folder. when I open http://127.0.0.1:8000/index/ I'm now getting the error in the title. I've pushed the modified project to https://github.com/kc1/s1. would you mind taking a look at this?

Bill

jfmatth commented 9 years ago

Bill, the problems your running into aren't related to my repo, but rather a basic understanding of how django works. Have you done the full tutorial, and then done it again (it sometimes takes multiple times until a methodology sinks in with me).

Another thing i would ask would be to understand GIT better. Basically, you should have done a change to your original repo, pushed up those changes, then I would be able to see what you changed :). Now I have to rely on what you show me, not that it isn't accurate, but it's not a complete approach.

I'll have a look later tonight when i get home, i don't have the right environment at work to do any troubleshooting.

If you have time, make sure to go over the tutorial :)

kc1 commented 9 years ago

Hi John, I'm sorry if I'm coming off as a noob. Please let me assure you that although I'm pretty new to django, I have put together 5 or so projects with it. The app I'm trying to deploy to django is a fully functional site when run locally. I didn't realize that it would be so difficult to deploy to openshift. I deploy to heroku all the time and its very easy, but I'd heard good things about openshift and decided to give it a shot. Anyway I appreciate you're taking the time to look at this project. My major question is wether the static files especially html templates are in the correct position.- Bill

jfmatth commented 9 years ago

Hi Bill, so i've got a site www.stocksonthebeach.com that uses this very same repo, and the static files work fine, just make sure to put them into the /static folder only. The settings file has all the necessary stuff configured to work locally from /static, and then collectstatic will deploy to wsgi/static when it's pushed to Openshift.

Openshift is very easy to use, especially with this repo (usually :) ).

As far as what you've pushed to github in kc1/s1, I don't see any files in your /static folder, and unless they are there in the repo, they won't get moved to /wsgi/static when you push to OS, so no, the S1 repo will not have any static content when it's pushed. Maybe the reason it's not there is you didn't push to github.

Typically, what I have in my openshift projects are two remotes configured for git, and if you follow the instructions for this repo, it has you create an Openshift app and clone it down (remote #1 - called Origin), and then you merge that with my repo (or a fork) and that is then remote #2 - Upstream. you can then push your changes to either side : git push origin master:master or git push upstream master:master, its up to you.

If you want to post the output of the git push to openshift here I'll have a look, that output is very helpful for troubleshooting Openshift issues.

HTH, good luck.

kc1 commented 9 years ago

Hi John, thanks again for your help on this. I now understand that when you say : "I don't see any files in your /static folder" you mean in the wsgi/static folder (I put em all in the /static folder). I have now run the manage.py collectstatic function, which moved everything into wsgi/static . I committed the results to https://github.com/kc1/s1 , so you can take a look if possible. I tried to run the project again but getting the same result "TemplateDoesNotExist at /index/"

"If you want to post the output of the git push to openshift here I'll have a look, that output is very helpful for troubleshooting Openshift issues." I'm not sure what you mean by "openshift here ". I'll be happy to push the results anywhere you want besides https://github.com/kc1/s1 .

Bill

kc1 commented 9 years ago

John, I just realized that in my initial https://github.com/kc1/s1 commit there were no files in /static folder ( what you said ) - sorry. In any case It doesn't change anything. I'm still getting the same error when running locally with the files in the static folder both before and after running collectstatic.The current commit is up to date.

jfmatth commented 9 years ago
  1. your static content only needs to go into /static, NOT /wsgi/static. Don't commit anything to the /wsgi/static folder, since that is not guaranteed to be there when you push to OS.
  2. Ill download your repo and try locally, but your error seems pretty simple :).
  3. The Openshift output I need is the result from the git push origin command from your laptop, just pipe that to a file, or go back and copy / paste the terminal and put that back here.

you can also just send to my personal email john at comp unique .com.

jfmatth commented 9 years ago

Dooh! Chalk one up for Bill, he found a bug ;).

Turns out, i forgot one setting in my settings file.

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(BASE_DIR, 'templates'),
)

Once I added that to the settings.py, it worked fine.

Sorry about that, but more importantly, thanks for finding this and being persistent enough to make me find it, seriously.

I'll make the fix, test it and upload this A.M.

let me know when you try it and it works for you.

J

kc1 commented 9 years ago
$ git push gh master
Username for 'https://github.com': kc1
Password for 'https://kc1@github.com':
Counting objects: 165, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (153/153), done.
Writing objects: 100% (158/158), 2.60 MiB | 1.89 MiB/s, done.
Total 158 (delta 10), reused 0 (delta 0)
To https://github.com/kc1/s1.git
   40d8e50..f8a3cba  master -> master
(r2)
dnir@WH2RAD42 /f/envs/r2/s1 (master)
$ git push origin master
Counting objects: 165, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (153/153), done.
Writing objects: 100% (158/158), 2.60 MiB | 4.63 MiB/s, done.
Total 158 (delta 10), reused 0 (delta 0)
remote: Stopping Python 2.7 cartridge
remote: Waiting for stop to finish
remote: Waiting for stop to finish
remote: Waiting for stop to finish
remote: Building git ref 'master', commit f8a3cba
remote: --> ACTION HOOK: pre_build <--
remote: Activating virtenv
remote: Checking for pip dependency listed in requirements.txt file..
remote: Requirement already satisfied (use --upgrade to upgrade): django>=1.7,<1.8 in /var/lib/openshift/5499d17bfcf93345f100015b/app-root/runtime/dependencies/python/vir
tenv/lib/python2.7/site-packages (from -r /var/lib/openshift/5499d17bfcf93345f100015b/app-root/runtime/repo/requirements.txt (line 1))
remote: Cleaning up...
remote: Running setup.py script..
remote: running develop
remote: running egg_info
remote: creating django_1.7_on_Red_Hat_Openshift.egg-info
remote: writing django_1.7_on_Red_Hat_Openshift.egg-info/PKG-INFO
remote: writing top-level names to django_1.7_on_Red_Hat_Openshift.egg-info/top_level.txt
remote: writing dependency_links to django_1.7_on_Red_Hat_Openshift.egg-info/dependency_links.txt
remote: writing manifest file 'django_1.7_on_Red_Hat_Openshift.egg-info/SOURCES.txt'
remote: reading manifest file 'django_1.7_on_Red_Hat_Openshift.egg-info/SOURCES.txt'
remote: writing manifest file 'django_1.7_on_Red_Hat_Openshift.egg-info/SOURCES.txt'
remote: running build_ext
remote: Creating /var/lib/openshift/5499d17bfcf93345f100015b/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/django-1.7-on-Red-Hat-Openshift.egg-
link (link to .)
remote: django-1.7-on-Red-Hat-Openshift 1.3 is already the active version in easy-install.pth
remote:
remote: Installed /var/lib/openshift/5499d17bfcf93345f100015b/app-root/runtime/repo
remote: Processing dependencies for django-1.7-on-Red-Hat-Openshift==1.3
remote: Finished processing dependencies for django-1.7-on-Red-Hat-Openshift==1.3
remote: Script /var/lib/openshift/5499d17bfcf93345f100015b/python//virtenv/bin/activate.fish cannot be made relative (it's not a normal script that starts with #!/var/lib
/openshift/5499d17bfcf93345f100015b/python/virtenv/bin/python)
remote: Script /var/lib/openshift/5499d17bfcf93345f100015b/python//virtenv/bin/activate.csh cannot be made relative (it's not a normal script that starts with #!/var/lib/
openshift/5499d17bfcf93345f100015b/python/virtenv/bin/python)
remote: --> ACTION HOOK: build <--
remote: Preparing build for deployment
remote: Deployment id is 69647711
remote: Activating deployment
remote: Script /var/lib/openshift/5499d17bfcf93345f100015b/python//virtenv/bin/activate.fish cannot be made relative (it's not a normal script that starts with #!/var/lib
/openshift/5499d17bfcf93345f100015b/python/virtenv/bin/python)
remote: Script /var/lib/openshift/5499d17bfcf93345f100015b/python//virtenv/bin/activate.csh cannot be made relative (it's not a normal script that starts with #!/var/lib/
openshift/5499d17bfcf93345f100015b/python/virtenv/bin/python)
remote: ---> ACTION HOOK: deploy <---
remote: Executing 'python /var/lib/openshift/5499d17bfcf93345f100015b/app-root/runtime/repo//manage.py migrate --noinput'
remote: Traceback (most recent call last):
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/app-root/runtime/repo//manage.py", line 10, in <module>
remote:     execute_from_command_line(sys.argv)
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_comm
and_line
remote:     utility.execute()
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
remote:     self.fetch_command(subcommand).run_from_argv(self.argv)
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
remote:     self.execute(*args, **options.__dict__)
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
remote:     output = self.handle(*args, **options)
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
remote:     executor = MigrationExecutor(connection, self.migration_progress_callback)
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
remote:     self.loader = MigrationLoader(self.connection)
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
remote:     self.build_graph()
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 179, in build_graph
remote:     self.applied_migrations = recorder.applied_migrations()
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
remote:     self.ensure_schema()
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
remote:     if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()):
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 167, in cursor
remote:     cursor = utils.CursorWrapper(self._cursor(), self)
remote:   File "/var/lib/openshift/5499d17bfcf93345f100015b/python/virtenv/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 18, in complain
remote:     raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
remote: django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more de
tails.
remote: Executing 'python /var/lib/openshift/5499d17bfcf93345f100015b/app-root/runtime/repo//manage.py collectstatic --noinput'
remote:
remote: 0 static files copied to '/var/lib/openshift/5499d17bfcf93345f100015b/app-root/runtime/repo/wsgi/static', 119 unmodified.
remote: Starting Python 2.7 cartridge (Apache+mod_wsgi)
remote: Application directory "wsgi/" selected as DocumentRoot
remote: $OPENSHIFT_PYTHON_WSGI_APPLICATION ENV VAR detected
remote: Application "mysite/wsgi.py" selected as default WSGI entry point
remote: --> ACTION HOOK: post_deploy <--
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To ssh://5499d17bfcf93345f100015b@s1-optionhomes.rhcloud.com/~/git/s1.git/
   40d8e50..f8a3cba  master -> master
jfmatth commented 9 years ago

Ok, I've pushed the changes to my repo, there are several ways to merge these in, but probably the easiest is to just change the settings.py file with the update I just made ( you can check the diff on github).

As for your git push output above, did you add a DB to your Openshift gear? It looks like it's missing the DB environment variables, which means theirs no DB gear in your app. Please check that you've run the steps below for your app:

rhc add-cartridge postgresql-9.2 --app django

OR

rhc add-cartridge mysql-5.5 --app django 

if you did, i'll need to set the output of this command from your computer

rhc apps

this will tell me what cartridges you've got installed.

That

kc1 commented 9 years ago

Hi John, I made the changes in the mysite/settings.py file and made a new commit to https://github.com/kc1/s1 , but I'm still getting the same "TemplateDoesNotExist at /index/" error. I did not add a db originally because I don't need it in this project. I can do that if you would like. Obviously it would be out of the order in the instructions though. will that matter?

jfmatth commented 9 years ago

Bill, I sent you a pull request for the fixes for your repo.

Have a Happy Holiday season and Merry new year, I hope the repo and Openshift make you fortunate.

J