How To: Setup your root App folder for the Cloud

AlessandroAlessandro
2 min read

This is a quick note on how to mix and match the ORM from Django into an application Flash or Tornado, consider the following folder structure:

mysite/
    app.py
    server/
        manage.py
        my_orm/
            __init__.py
            admin.py
            apps.py
            models.py
            test.py
            view.py    
        mysite/
            __init__.py
            settings.py
            urls.py
            asgi.py
            wsgi.py

The structure provided has a Flask or Tornado application on the app.py file. However, the previous developer did not know how to use SQL and so decided to use an Object Relational Model (ORM) and decided on the one provided by Django. The web application runs well, the database access works with the ORM as expected and everything is great. Now, the developer leaves, you inherit the code base and manage to run it locally and it works ok. You might not love the ORM, but it is easy enough that the junior programmer can contribute to the code without having to understand SQL.

Lots of developers do not know how to use SQL, if you don't know you should learn

The application performs and runs well in the internal VMs. However, the project needs to be on the cloud as the company is moving now towards cloud-only deployments as it is the new company mission to reduce cost. The code base is deployed to your providers, we are using MS Azure, the local scripts are run to update the data model as you have switched the ORM settings to using environment variables so you can connect to your cloud database and everything seems to be going smooth. Now we push the server code to an App Service, and BOOM, everything is NOT peachy! The structure of your code is having issues finding the correct folders for the ORM, how do we fix this? We need to add to the python path the location of the Django section of the code and we do that as follows:

The piece code above we set the location of our Django settings to our Python path, then we call the django.setup() method setting up our ORM properly. This has to happen before your main application launcher. After it, everything with the ORM is working again.

This little piece of code can save you a lot of headache

0
Subscribe to my newsletter

Read articles from Alessandro directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Alessandro
Alessandro

I am a developer from the Greater Boston area, I have a M.S. in Computer Science and Engineering from the University of Connecticut, focused on Bayesian Networks and Bayesian Knowledge Bases. I have experience working on 3D laser scanners, motion platforms, DARPA projects, 3D simulations using the Unity game engine for robotics in synthetic environments (game generated and scanned), mobile development in both Android and iOS. My strengths are in rapid prototyping and taking an idea into a release candidate. The process is a winding road that takes a lot of time