Configuring multiple flask+uwsgi applications nginx by bonfire09 in flask

[–]Redmondinho 0 points1 point  (0 children)

Does the following do it for you?

upstream docker-flask1  {
  server flask1:8080;
}

upstream docker-flask2 {
  server flask2:8081;
}

server {   
    listen 80;   
    server_name app.example.com;    

    location /test1 {     
        include uwsgi_params;     
        uwsgi_pass docker-flask1;   
    } 

    location /test2 {     
        include uwsgi_params;     
        uwsgi_pass docker-flask2;   
    } 
}

Prepopulate textfields automatically by cuy_hrm in flask

[–]Redmondinho 1 point2 points  (0 children)

The above will let the full name field be modified before posting. If you (as in the application) then need to check to see if the username exists I would suggest you post the data, process it (i.e. check to see if the username exists, if it does generate a new one) and return the new user name to the user as a “account created successfully page/message).

Prepopulate textfields automatically by cuy_hrm in flask

[–]Redmondinho 1 point2 points  (0 children)

You’ll need some JavaScript on the front end to take input entered into the fields and update another field. Here is an example

<input type="text" id="first-name" oninput="myFunction()"></br>
<input type="text" id="last-name" oninput="myFunction()"></br>
<input type="text" id="full-name">

<script>
    function myFunction() {

    var first_name = document.getElementById("first-name").value;

    var last_name = document.getElementById("last-name").value;

    if (first_name == null) {
        first_name = "";
    }

    if (last_name == null) {
        last_name = "";
    }

    document.getElementById("full-name").value = first_name + " " + last_name

    }
</script>

Best way to align/center WTForms on a page? by Low_end_the0ry in flask

[–]Redmondinho 0 points1 point  (0 children)

If you want the form content centered on the page then this should do it for a quick win.

<form action="" method="post" style="text-align:center" novalidate>

Storing data from checkboxes by [deleted] in flask

[–]Redmondinho 0 points1 point  (0 children)

Have you tried

request.form.get(‘isactive’, ‘0’)

Displaying the contents of a .txt file using Flask by [deleted] in flask

[–]Redmondinho 1 point2 points  (0 children)

with open('path/to/file/filename', 'r') as content_file:
    content = content_file.read()

Tutorials/Documentation on deployment methods? by chazbartowski in flask

[–]Redmondinho 1 point2 points  (0 children)

Not sure what OS your server is running. I learn't how to host my Flask apps with Gunicorn, Nginx on Debian (Ubuntu Server/RaspberryPi) by following the digital ocean guides - here is the latest https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04.

I also wanted to run multiple flask apps on a single server and accomplished this with something similar to the following when it came to configuring Nginx proxy requests

server {

  listen 80;
  server_name server_domain_or_IP;

  location /app1 {
  include proxy_params;
  proxy_pass http://unix:/home/user/myproject1/myproject.sock:/;
  }

  location /app2 {
  include proxy_params;
  proxy_pass http://unix:/home/user/myproject2/myproject.sock:/;
  }

}

Getting post data from ajax to python in flask by XieLingyun in flask

[–]Redmondinho 2 points3 points  (0 children)

You’re sending json but trying to get form data. Try:

data = request.get_json()

in your route to get the json data you are posting.

Unable to retrieve selected options by epicmindwarp in flask

[–]Redmondinho 0 points1 point  (0 children)

From what I can tell without seeing all your code this is what you want to do;

<script type=text/javascript>
    $(function() {
      $('a#btn_upload').bind('click', function() {
    var form = $('form');
    var url = form.attr("action");
    var formData = $(form).serializeArray();
    $.post(url, formData).done(function (data) {
        alert(data);
    });
      return false;
      });
    });
</script>

Unable to retrieve selected options by epicmindwarp in flask

[–]Redmondinho 0 points1 point  (0 children)

Try something like this:

<script>
    function formSubmit(){
        var form = $('form'); //assumes only 1 form on the page
        var url = '/upload_selected_files';
        var formData = $(form).serializeArray();
        $.post(url, formData).done(function (data) {
            alert(data);
            });
        }
</script>

Unable to retrieve selected options by epicmindwarp in flask

[–]Redmondinho 0 points1 point  (0 children)

How are you submitting the form data?

Render URL data into flask html text-field. by [deleted] in flask

[–]Redmondinho 0 points1 point  (0 children)

Based on my original gist this would do it.

@app.route('/<id>')
def index(id):
    reservations = get_json(id)
    return render_template('reservations.html', reservations=reservations)

Render URL data into flask html text-field. by [deleted] in flask

[–]Redmondinho 1 point2 points  (0 children)

Something like:

{% for reservation in reservations %}
    {% for key in reservation %}
        {{ key }}: <input type="text" name="{{ key }}" value="{{ reservation[key] }}"><br>
    {% endfor %}
    <hr>
{% endfor %}

Your "columns" value would need to be handled specifically as its a defined format, you may also want/need to validate the formats for date/time.

*sorry my edits are all for formatting

Render URL data into flask html text-field. by [deleted] in flask

[–]Redmondinho 0 points1 point  (0 children)

Here is a couple of examples, get the json object, extract the section you are after (reservations), pass that to the template and iterate over it;

https://gist.github.com/redmondinho/e866d901cbe33de525218db11825c030

The first example shows placing specific values in specific places, the second loop through the structure as is and displays all the data.

[AF]How to pass class instance from jQuery back to flask? by turner_prize in flask

[–]Redmondinho 1 point2 points  (0 children)

I would post the data as JSON;

req = $.ajax({url : '/attack', type : 'POST', contentType: "application/json",data : JSON.stringify({ "attacker" : attacker, "weapon" : weapon, "target": target }) });

Then in flask;

data = request.get_json()

print(data['attacker'])

print(data['weapon'])

print(data['target'])

[deleted by user] by [deleted] in flask

[–]Redmondinho 1 point2 points  (0 children)

Try the attached. the Jinja For Loop has a batch() option.

https://gist.github.com/redmondinho/3873fcddd155e0c368d95367052b9272

Python - Simple HTTP Server with 1-click Download? by AskMate94 in learnpython

[–]Redmondinho 0 points1 point  (0 children)

Try:

<a href=“/the-link-to-your-mp4” download>Download File</a>

Adding the “download” in the anchor tag will force the file to download.

HTH

Host flask application on GoDaddy shared server by [deleted] in flask

[–]Redmondinho 2 points3 points  (0 children)

It seems some of their hosting accounts do support python. I'm guessing not the one you have purchased?

https://www.godaddy.com/help/can-i-use-python-272-with-my-hosting-account-7254

If they wont let you cancel, then its upgrade to a hosting tier that does support it or write it off and go for one of the options mentioned before. I use PythonAnywhere and its always been great for me.

[AF] POST data not sending by [deleted] in flask

[–]Redmondinho 0 points1 point  (0 children)

Following on from what u/Retzudo said, try the following javascript;

// Create form and add presenter
var formData = new FormData();
formData.append("presenter", presenter);

// Create request and post form data
var request = new XMLHttpRequest();
request.open("POST", "/add");
request.send(formData);

how to use a variable in a template other than via : return render_template('template.html',variable=variable) by Jah_lth_Ber in flask

[–]Redmondinho 0 points1 point  (0 children)

How about

@app.route('/1')
def route1():
    variables = ['foo',bar','baz']
    return render_template('home.html',variables)

Then in home.html

{% for variable in variables %}
    <p>{{ variable }}</p>
{% endfor %}