Forums

Flask app only showing raw html template

Hello everyone, sorry if this is a wrong/misleading title. I don't quite know the terminology to use as this is my first full fledged Python program and first time touching web development stuff. I'm running into a problem where only the plain "index.html" shows when I try to go to my site: http://espityle.pythonanywhere.com. It doesn't use any of the CSS stylings or Jinja2 rendering, the links are all broken, it doesn't do anything except serve up this one html page.

I checked the error logs and this is what is shown:

2015-07-30 14:17:36,481 :ImportError: No module named 'peewee'
2015-07-31 04:04:25,069 :Exception on / [GET]
Traceback (most recent call last):
File "/home/espityle/.virtualenvs/storystack/lib/python3.4/site-packages/peewee.py", line 2740, in get
return clone.execute().next()
File "/home/espityle/.virtualenvs/storystack/lib/python3.4/site-packages/peewee.py", line 1957, in next
obj = self.iterate()
File "/home/espityle/.virtualenvs/storystack/lib/python3.4/site-packages/peewee.py", line 1939, in iterate
raise StopIteration
StopIteration

During handling of the above exception, another exception occurred:

As you can see there's more to follow, but I'm guessing it stems from not being able to import Peewee? I made sure to provide the path to the correct virtualenv in the Web App dashboard and I have the same version of Peewee installed into the virtualenv as on the computer where the code was written. Of course, it works fine on my local machine! Haha.

The server logs show:

2015-07-31 04:17:53 Python version: 3.4.0 (default, Jun 19 2015, 14:24:19)  [GCC 4.8.2]
2015-07-31 04:17:53 Set PythonHome to /home/espityle/.virtualenvs/storystack 
2015-07-31 04:17:53 *** Python threads support is disabled. You can enable it with --enable-threads ***
2015-07-31 04:17:53 Python main interpreter initialized at 0x18c6170
2015-07-31 04:17:53 your server socket listen backlog is limited to 100 connections
2015-07-31 04:17:53 your mercy for graceful operations on workers is 60 seconds
2015-07-31 04:17:53 setting request body buffering size to 65536 bytes
2015-07-31 04:17:53 mapped 333952 bytes (326 KB) for 1 cores
2015-07-31 04:17:53 *** Operational MODE: single process ***
2015-07-31 04:17:53 WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x18c6170 pid: 20495 (default app)
2015-07-31 04:17:53 *** uWSGI is running in multiple interpreter mode ***
2015-07-31 04:17:53 spawned uWSGI master process (pid: 20495)
2015-07-31 04:17:53 spawned uWSGI worker 1 (pid: 20497, cores: 1)
2015-07-31 04:17:53 spawned 2 offload threads for uWSGI worker 1
2015-07-31 04:17:54 announcing my loyalty to the Emperor...

I'm not sure if any of this information I'm providing is at all relevant, but I really want to try to provide as much info as I can. The code that I'm trying to make work is the same code on my github repo here: https://github.com/espityle/StoryStack. This is the same code I was using on my local machine. The database is a sqlite database.

Sorry for such a long rambling, this site is awesome and I've had a lot of fun playing around with this and learning about Flask, websites, etc. Thanks a bunch!

hmm. seems like that error happened before you last reloaded the webapp

Could it be something like you don't have any authors/stories in the database and so your template is not loading correctly? (vs locally you already had authors/stories from previous runs) I see that some other url paths on your webpage seem to be loading fine (eg: espityle.pythonanywhere.com/story), which does render templates correctly. Maybe you can try to figure out what the difference is between those two?

I think that you were on the right track Conrad. I was definitely operating with an empty database. I added some filler content to the database. The site has complete functionality now EXCEPT for the index page at espityle.pythonanywhere.com. If you go to espityle.pythonanywhere.com/1 which serves the same page just with the specified database entry of id = 1 it works just fine. They even use the same route in my app.py.

I'm sure the bug is in my code somewhere, but I can't seem to figure it out. I tried rewriting some of my app.py to see if it made a difference and it didn't.

http://espityle.pythonanywhere.com/ looks fine at the moment -- is there something I'm missing? Or did you manage to work out the problem?

Someone in /r/learnpython helped me out. The error was that I thought I was supposed to put my /templates/ in the web app dashboard where you put static files. Took that path out of the web app dashboard and it's all fine! Thanks so much for the help. Really love this service!

Ah, that would make sense! Glad you got it working :-)