OK, here’s the simplest way/setting for Django. I am using mac, but it should be similar for other linux.
First. Installing an official release.
- Download the latest release from download page.
- Untar the downloaded file (e.g. tar xzvf Django-X.Y.tar.gz, where X.Y is the version number of the latest release).
- Change into the directory created in step 2 (e.g. cd Django-X.Y).
- If you’re using Linux, Mac OS X or some other flavor of Unix, enter the command sudo python setup.py install at the shell prompt.
After install it, run python in the command line, and check:
Second, is to Configure your database and create your first app.
From the command line, cd into a directory where you’d like to store your code, then run the following command:
django-admin.py startproject mysite
mysite/ manage.py mysite/ __init__.py settings.py urls.py wsgi.py
Now run the server by doing:
python manage.py runserver.
You will see somthing like this in your terminal:
Validating models... 0 errors found.Django version 1.4, using settings 'mysite.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
This is where you can make your ico file : http://www.favicon.cc/
Ico file is the icon that displays in the address bar of your web browser when you connect to a website.
When using Apache + python-cgi, I encounter this error:
<type ‘exceptions.RuntimeError’>: Failed to create /$dirstring$/common/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data
An official explanation of MPLCONFIGDIR is here.
MPLCONFIGDIR This is the directory used to store user customizations to matplotlib, as well as some caches to improve performance. If MPLCONFIGDIR is not defined, HOME/.matplotlib is used by default.
It turns out that on my windows machine HOME/.matplotlib is now writable. Here’s a way to simply bypass this problem.
Find out the place where you first import matplotlib, right before it, set the $HOME dir to a temporary dir where it’s writable:
For example, I was importing matplotlib in an indirect way through “from scipy.cluster.vq import kmeans2“, so right before it, do
os.environ[‘HOME’] = r’C:\……\Apache2.2\htdocs\tmp’
from scipy.cluster.vq import kmeans2
To Set Up a Server on my mac.
- Goto Preference: Sharing, Check the Sharing View
- Now the apache is running, to do a test: put: localhost in your browser, you will see “it works!”
- When you check the box for Sharing View, you will be notified that there are two different websites are now available on your computer
- 1. Personal Website: http://you-computer-name/~youraccountname
- The Sites folder in in your home folder : ~/Documents/Sites
- 2. Computer Website: http://your-computer-name/
- The Site Folder in <Library/WebServer/>
- There are 3 subfolders under this folder: a) CGI-Executable; b) Documents; c) Share
- You should put your executables in this folder, such as the below python code:
print “Content-type: text/html”
print “Test Page”
Name it as ‘test.py’, and in the terminal change it to
$ sudo chmod 755 test.py
Now you can run it by : http://localhost/cgi-bin/test.py
Here’s a useful link: http://www.editrocket.com/articles/python_apache_mac.html
Also here’s how to share a folder: http://www.macworld.com/article/1140370/pythonserver.html
In Terminal, first cd to the folder you’d like to make available via the Web server. For example, cd ~/Pictures to switch to your user’s Pictures folder. Next, you activate Python’s built-in Web server with this command: python -m SimpleHTTPServer (and yes, capitalization counts). Press Return, and you’ll see a message stating Serving HTTP on 0.0.0.0 port 8000 .... The important bit there is the port number (8000). (You can use a different port number by simply including it at the end of the command, like so: python -m SimpleHTTPServer 8080.) To access the server from the machine you’re running the Python server on, switch to a Web browser, and enter http://localhost:8000 (replace 8000 with the port you used, if you didn’t use the defaut) in the URL bar. When you press Return, you’ll see a listing of all files in the directory. Depending on what types of files are there, and which browser you’re using, you can then click on files to view them in the browser. In my testing, Firefox works better than Safari, as Safari wants to download file types it doesn’t know how to handle while Firefox will often let you open them with a helper application. To access the server from another machine on your network, you need to know the server computer’s name. You can find this in the Sharing System Preferences panel, in the aptly-named Computer Name section of the panel. Just below the computer’s actual name, you’ll see a line that begins Computers on your local network can access…, followed by the name they’ll need to use to do so. Typically, this is simply the Computer Name followed by .local—so if the machine’s name is OctoMac, for instance, you can then access the server by entering http://OctoMac.local:8000 in your browser’s URL bar.