1

I am developing a web page using jinja2 template and alsk framework .

My folder architecture is as follow

Web
|-->static
       |-->css
       |-->js
       |-->img
|-->templates
       |-->test1
            |-->alaram1.html
       |-->test2
            |-->alarm2.html
|-->modfunctions
       |-->test1
             |-->main.py
       |-->test2
             |-->main.py

I have separate main.py inside test1 and test2 folders. As of now, i'm getting inside 'modfunctions->test1' folder , running python script and getting my output on '0.0.0.0:5000/test1' . Similarly, when I get into 'modfunctions->test2', run main.py. I am getting my output on '0.0.0.0:5000/test2'in browser.

But I want a single .py script using which I can run both test1 and test2 modules same time

here I have my main.py script

from flask import render_template, request, redirect

from flask import Flask
from flask import render_template, request, redirect

app = Flask(__name__, template_folder='/home/web/templates', static_folder='/home/web/static')

@app.route('/test1', methods=['GET','POST'])
def test1():
    if request.method == 'GET':
        return render_template('test1/alarm1.html')

    if request.method == 'POST':
        return render_template('test1/alarm1.html')

if __name__ == "__main__":
app.debug = True
app.run(host='0.0.0.0', port=5000)

similarly for test2-main.py

    from flask import render_template, request, redirect

from flask import Flask
from flask import render_template, request, redirect

app = Flask(__name__, template_folder='/home/web/templates', static_folder='/home/web/static')

@app.route('/test2', methods=['GET','POST'])
def test2():
    if request.method == 'GET':
        return render_template('test2/alarm2.html')

    if request.method == 'POST':
        return render_template('test2/alarm2.html')

if __name__ == "__main__":
app.debug = True
app.run(host='0.0.0.0', port=5000)

Please share some solution

user2955338
  • 59
  • 1
  • 2
  • 13
  • Why do you seperate it ? why don't you put all code in one file ? – furas Jun 23 '14 at 10:51
  • @furas . I wanted to handle so many urls.If I keep all inside a single file it looks so complex. so I want to separated to separated them into multiple files – user2955338 Jun 23 '14 at 11:01
  • 2
    [how-to-divide-flask-app-into-multiple-py-files](http://stackoverflow.com/questions/11994325/how-to-divide-flask-app-into-multiple-py-files) – furas Jun 23 '14 at 11:10

0 Answers0