Joel
Joel

Reputation: 673

Python and App Engine project structure

I am relatively new to python and app engine, and I just finished my first project. It consists of several *.py files (usually py file for every page on the site) and respectively temple files for each py file. In addition, I have one big PY file that has many functions that are common to a lot of pages, in I also declared the classes of db.Model (that is the datastore kinds).

My question is what is the convention (if there is one) of arranging these files. If I create a model.py with the datastore classes, should it be in different package? Where should I put my template files and all of the py files that handle every page (should they be in the same directory as the one big common PY file)?

I have tried to look for MVC and such implementations online but there are very few.

Thanks,

Joel

Upvotes: 6

Views: 1381

Answers (2)

Jason Hall
Jason Hall

Reputation: 20920

Typically I organize like so:

project/
  main.py
  models.py
  app.yaml
  index.yaml
  templates/
    main.html
    foo.html
    ...
  styles/
    project.css
  js/
    jquery.js
    project.js
  images/
    icon.png
    something.jpg

And I have all of my handlers in main.py, all of my models in models.py, etc.

If I have a lot of handlers, and I can easily split the functionality of some handlers from the others (like taskqueue handlers vs. request handlers vs. xmpp/email handlers) I'll add another foo_handlers.py to the mix, but usually I just cram them all in main.py

But then again, I tend not to write hugely complex Python App Engine apps...

Upvotes: 3

systempuntoout
systempuntoout

Reputation: 74134

I usually organize my projects in this way:

project 
  main.py
  README
  models
      bar.py
      foo.py
  views
      foolist.hml
      barlist.hml
  controllers
      controller1.py
      controller2.py
  api
      controllerapi.py
  helpers
      utilities.py
  lib
      extfoo.py
  db
     foo.db
  test
     test.py

Look at this post; it's a really great article on how to structure a project (not in python but it does not matter).

Upvotes: 3

Related Questions