Enabling the web2py profiler on pythonanywhere - profiling

There is a (seemingly) simple way to generate profiler information about a web2py installation, by just adding a -F flag. How, if it is possible, would this be enabled on a web2py site hosted on http://pythonanywhere.com?

In the WSGI file for your web app, you currently have a line:
from gluon.main import wsgibase as application
replace it with:
from gluon.main import appfactory
application = appfactory(profiler_dir="/tmp")
and your web2py app will log profiling data to the /tmp directory.

Related

I want my django app to get a file from a remote machine

I need my django app to scp a file on a remote server into the django 'media' folder.
Is spawning an scp session with pexpect in my django app the best way to go about this?
Alternatively, are there libraries I can use in my django app to do this?
Any help is much appreciate.

How to run Django function in Pycharm?

I have some internal utilities I want to develop for my Django project. These are utilities that I need to run mostly in my DEV environment, not in production.
I want to be able to call these from my PyDev IDE or Terminal. Is there a way to call functionality in my Django project without creating a view and using a URL to access it?
I've done several Google searches, but nothing is coming up.
If you open the "Python Console" on Pycharm, it will automatically set django up and then you can basically do anything you could do on a Django view. You can write your function anywhere and import and call them. To do the setup manually, you'll need these for lines of code after launching a Python interpreter:
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'path.to.your.settings')
import django
django.setup()
# Write code using Django models here
you could import them to your PyCharm console starting script. In settings under: Build, Execution, Deployment -> Console -> Python Console -> Starting script

ubuntu django and apache, cannot find the site

I am brand new to web app development and thought I would try django as I am familiar with python. I followed the following guide: http://www.lennu.net/2012/05/14/django-deployement-installation-to-ubuntu-12-dot-04-server/ to deploy a django page to the letter. However, I now realize that this guide was for the server version of the OD and i'm running the desktop version. When I try to open my site in chrome (amitash.r) it fails with a page not found. Now when I open localhost, I get an internal server 500 error. All my config files are exactly as stated in the guide. Any fixes?
Can you post your mod_wsgi script and Apache VirtualHost file?
Following the instructions from the link you gave, the mod_wsgi script should be in:
/srv/my_project/app/conf/apache/django.wsgi
The VirtualHost file location from the link should be:
/etc/apache2/sites-available/DOMAIN
Make sure you enabled your site. If you named your file DOMAIN, like the instructions, you should enable the site using:
a2ensite DOMAIN

Google App Engine and Django support

I'm trying to deploy my Django app to Google App Engine (GAE) as per this document. I created and configured a Google Cloud SQL instance, as described in that document. I use PyCharm as development environment and created a GAE project with Django support.
I configured a local server to point to the GAE server. When I try to launch the GAE local server in PyCharm, it's raising exceptions on an improperly configured database in SETTINGS.PY:
google.appengine.ext.django.backends.rdbms' isn't an available database backend
I can see from the stack trace that the local server is using the Django version in /Library/Python/2.7/site-packages while I presume it should use the one in /usr/local/google_appengine/lib.
What would be the best way to solve this given that I have other Django projects as well that should use the Django version in /Library/Python/2.7/site-packages? If I modify my PYTHONPATH to include the GAE version of Django, would not all my projects be referencing that version of Django?
EDIT: To be more precise, the GAE local server starts just fine but throws the mentioned stack trace when I do a syncdb task to update my database.
EDIT 2: In PyCharm Settings under Python Interpreter, I found the possibility to modify paths and added the Django 1.4 version as distributed with GAE SDK. When I start the GAE development server, I can actually see it uses the Django version from the GAE SDK but it still crashes on the database definitions:
Error was: No module named google.appengine.ext.django.backends.rdbms.base
EDIT 3: I ran into problems when trying to deploy an existing Django app using the tutorial. See this separate question.
Looks like PyCharms call of syncdb is using the wrong Django installation.
google.appengine.ext.django.backends.rdbms is not part of the official Django distribution, but it is part of GAEs django.
My GAE django is in /usr/local/google_appengine/lib/
If you're on linux/OS X you could add this to your .bashrc/.bash_profile and make syncdb use this:
export GAE="/usr/local/google_appengine"
export PYTHONPATH="$PYTHONPATH:$GAE:$GAE/lib/django_1_4"
export PATH=${PATH}:$GAE/lib/django_1_4/django/bin/
export PATH=${PATH}:/usr/local/mysql/bin
I wrote a tutorial about using Django with GAE and Google Cloud SQL. There might be some relevant infos there as well.

Installing, configuring and developing for django on ubuntu 10.10 server

I wanted to start getting into developing with Django, however, I am unable to figure out how to make it work. I have installed apache2, I have tried many tutorials on configuring apache to run Django, but I just do not understand how it all works together. Can someone give me a dummies guide on how to install it, how things work, and why?
The best way to link between Django and Apache is using WSGI. You will need to install the mod_wsgi apache module to do this.
Next step: modify the apache configuration file to designate where you want the root of your django website.
WSGIScriptAlias / /path/to/mysite/apache/myApp.wsgi
Next, you should create the wsgi file. This is what initializes your django application. An example wsgi file looks like this
import sys
import os
sys.path.insert(0,os.path.normpath(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0,'/path/to/directory/containing/application')
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'twitmycity.settings'
application = django.core.handlers.wsgi.WSGIHandler()
Once you have this, restart apache
sudo /etc/init.d/apache2 restart
Now, point your browser to the root directory where you established the wsgi handler. This should bring you to the root to your django application. I hope this helps!
Also note, when you make a change to your application, you need to refresh the modified time on the wsgi file to prevent wsgi from just using a cache version of the django application. To do this, execute
touch myApp.wsgi