user2950593
user2950593

Reputation: 9617

Deploy flask app python

I have python flask app which is written on windows. I am trying to deploy it using pythonanywhere.com hosting.

I have following structure:

app.py - my main application
-templates - here I have .html files
-default - here I have img, js, css subfolders.

So I have a confusion with files structure on linux systems. For example this is filestructure on pythonanywhere.com

>      .bashrc              2015-02-19 17:55    546 bytes
>      .gitconfig           2015-02-19 17:55    266 bytes
>      .profile             2015-02-19 17:55    79 bytes
>      .pythonstartup.py    2015-02-19 17:55    77 bytes
>      .vimrc               2015-02-19 17:55    4.4 KB
>       README.txt

So where should I put up my files? There on hosting?

Upvotes: 1

Views: 383

Answers (1)

hwjp
hwjp

Reputation: 16071

I recommend a folder structure like this:

home
└── yourusername
    └── myflaskapp
        ├── app.py
        ├── default
        │   ├── css
        │   ├── img
        │   └── js
        └── templates
            └── index.html

On PythonAnywhere, you can go to the "Files" tab to create folders and upload files, one by one. If you have lots and lots of files, you might want to check out the guide to getting files in and out of PythonAnywhere

Once you've got your files uploaded, you'll want to do the following:

  • Go to the "Web" tab and set up a new web app
  • Choose "Manual Configuration"
  • Edit the wsgi file, and add /home/yourusername/myflaskapp to the sys.path
  • add a line like from app import app as application (check out this guide if you need help with sys.path / import error issues)

Hit reload, and you should see your web app.

Then to get the css and javascript working, you'll probably want to set up a static files mapping.

  • On the "Web" tab, enter a new Static files entry,
    • with the URL /static/ (or maybe /default/, it depends on what you put in your templates),
    • and the path should be /home/yourusername/myflaskapp/default.

Upvotes: 2

Related Questions