B
B
beginer1232016-07-25 18:08:22
Flask
beginer123, 2016-07-25 18:08:22

Python application on Windows and Ubuntu how to organize?

Hello, I'm trying to figure out how to properly organize work on my project.
I use the Flask framework
, I work locally under windows, I bought a VPS with ubuntu remotely, but immediately a lot of questions
arise . on ubuntu, I found a whole article (much more difficult) https://www.digitalocean.com/community/tutorials/h... there you need to create several files, subfolders, etc. the structure will look something like this

|--------FlaskApp
|----------------FlaskApp
|-----------------------static
|-----------------------templates
|-----------------------venv
|-----------------------__init__.py
|----------------flaskapp.wsgi

Actually the question is: How can I organize all this on the local and remote repositories?
I will also have such constructions in the script (opening various files)
file = open('/var/www/FlaskApp/FlaskApp/myfile', 'w')

But on Windows I will not have such a path, i.e. when pushing to the VPS repository, will I have to change this constantly?
Do I understand correctly that I should follow the instructions above to make a start project on the server from the beginning, and then just copy it all (including the venv folders) to the local computer? so that later when pushing the structure was the same?
But here, again, the question arises, what if I have different pieces of code, depending on which server it is (local remote)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2016-07-25
@deliro

1) Absolute paths are evil. There is no reason for you to use them.
2) There is an os module, which has the os.path.join function, which collects the names of folders / files, adding the necessary slashes.

A
Alexey Cheremisin, 2016-07-25
@leahch

As for the files, make a settings.cfg file, remove at least the path to your application in it.

import platform

if platform.system() == 'Linux':
   MYAPPPATH = "/var/www/FlaskApp/FlaskApp"
else: 
   MYAPPPATH = "C:/FlaskApp/FlaskApp"

Well, or directly in the application launch code
import platform
if platform.system() == 'Linux':
  app.config["MYAPPPATH"] = "/var/www/FlaskApp/FlaskApp"
else: 
   app.config["MYAPPPATH"] = "C:/FlaskApp/FlaskApp"

Further in the code
On the second question, flask has a built-in server, but it's for debugging and development. In combat mode, it is strongly recommended to run from under a normal server under WSGI. Here, it will be necessary to write an additional wsgi.py (depending on the type of launcher) for a dozen lines - there are wagon examples in the network.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question