Hello :) My task is to write a web framework for a Python program with some massive calculations, which are desired to be executed at proper server and the result should be sent to the browser after it's calculated. My question is - is Django the right framework for that purpose? I tried to find out where Django executes scripts, but I haven't found any satisfying answer, so I hope that I would find one here.
Thank you for any attention.
django is a server side application
Related
Im creating a server in Python that receives POST requests, process the information in the request using some scripts (sometimes using a database) and send back a answer in JSON format. Im searching for a way to run this server and code in the cloud, in a way that i dont need my PC turned on for it to work, because my connection is very unstable.
There are a lot of web hosting companies out there, you just need to find the one that is right for you.
My personal favorite for python apps is heroku, but there are many out there. AWS is another popular one.
In future when asking questions, try to do more research before hand, and try to be more specific with questions. It would have been useful to know what kind of database you are using, or whether you're using flask or django.
Currently I'm learning to work with the Django framework. I'm trying to make a dashboard that can collect some output of scripts I want to make (in Python). I can't really find a conclusive answer to how to pipe the output of a python script through Django in my app. For instance, I want a script that runs a couple of ARP calls and pings in a network and have the output in a dashboard. Of course python is probably not the only language I'm going to use for scripting, maybe I will use some Bash or Golang also.
I hope someone is able to help my in the right direction.
Thank you in advance!
I have done this for a coding portal that I made.
What I did is, opened a thread that executed code and put the output in a file that was linked to a model filefield
Then I simply collected the contents of the file in the template (dashboard in your case)
If interested,
models.py (Check for Submission and Result model)
Code processing file (This is the file that actually runs the code and collects)
I was in a hurry when I made this. The way I have processed code is highly inefficient and should not be used. But you will get the idea
I've gotten use to using print in my python code to show contents of variable and checking the shell output.
But i have now migrated all my work onto a online server. Pythonanywhere
I don't have the foggiest idea how to do the same now?
Can someone point me in the right direction?
Print to web console? To a file? Or even to the shell session?
Thanks
On production server your print statements will output log to your webserver log files
In case of pythonanywhere there are three log files
Access log:yourusername.pythonanywhere.com.access.log
Error log:yourusername.pythonanywhere.com.error.log
Server log:yourusername.pythonanywhere.com.server.log
those logs are accessible in your web tab page.
The logs you are looking for will be in server.log
As mentioned in Serjik's answer you can see the output of the console via the server log link on PythonAnywhere.
However the much better way to approach this is to use the Python logging module.. Using this module will solve many of these problems for you and solve many issues you may not have thought about (like thread safety). This lets you do things like filter log messages by severity and a whole bunch of other things.
To get started with that I would recommend having a look at the basic logging tutorial.
I am looking to create a very basic website that has a single feature. This feature works as follows:
1) The user inputs a URL to a website
2) My website will scrape the given website for necessary information
3) Apply whatever logic I need and return the processed information as a string
4) Allow user to download returned data in .txt format.
I am working on this project with one collaborator, and he has created the scraping and logic (steps 2 and 3) in Python. I have looked around stack overflow to see if it is possible to execute python scripts in a website, and the consensus seemed to be that I will require a server that executes python, and then make HTTP requests to my server.
Unfortunately, I'm quite a junior developer and lack a lot of understanding regarding web dev, and my attempts to "dive in" have left me with more questions than answers. We have a deadline that is approximately 3 days from now, and the only part that remains is to set up a server that can execute a specific python script upon HTTP requests.
I think that the source of my confusion is a lack of understanding regarding how exactly a server works, and was hoping that the kind folks here at stack overflow could help me in:
1) better understanding what's going on "under the hood" on the server side after an HTTP request arrives (or better yet, how does an HTTP request even arrive at all?)
2) Explain to me like I'm 5 what I'll need to do to deploy my website - namely all the in-between steps that receive little attention from the other posts here at stack overflow.
Some example questions that run through my head are below:
What type of server will I need?
How will I know if it can run Python?
How does the server know that I want to execute a certain script, while upon a user entering a my website's homepage URL, land at the home screen?
I've also read up on "middle layers" such as 'CGI' - what does this accomplish?
Is setting up a server reinventing the wheel?
enter code here
Is there already a service out there that does what I'm looking for?
I've accomplished a similar project overnight with a Python web framework called Django, simply by following their official tutorial: https://docs.djangoproject.com/en/1.7/intro/tutorial01/
Django abstracts away all the web stuff for you and there's plenty of documentation on deploying it in various environments. With such deadlines I suggest you to just follow the tutorial above and eventually adapt the example to your use case testing it on Django's built-in web server, then follow a guide on deploying Django projects in your production environment.
I love django, and I like flex. Django for it's cool debugging system (those yellow pages helps a lot to find bugs in my code), and flex for it possibilities.
Recently I come across a problem. If I create a form in flex and then communicate with the django server, I can't see any debugging info (when the exception happens in django).
Not sure, if there is a way to get the debugging info, because it is not accessible in command line (no error output), or in firebug....
Also I tried to create a quick html form, and post same data as I send from flex form, but it's a bit of pain to be honest.
Will be happy to listen how do you solve the problem
I've used firebug to debug the flex side of things. But I've been using json or XML for communication between the two. Since flash uses the browser to do the network stuff, the request should be visible in the net tab of firebug.
To debug the django side of things, you have a few options.
If you're using the django dev server, you can add print statements to find out what's going on.
You can write a unit test to see if the django side of things is doing what you expect it to, given known data.
You can use the pyDev debugger to run the django dev server and step through your code.
I use a combination of these to debug my code.