Showing posts with label Programming-Knowledge. Show all posts
Showing posts with label Programming-Knowledge. Show all posts

Monday, March 4, 2013

Django with MySql set up (on Ubuntu)

This post describes the installing Django with MySql set up in a succinct way. 
Install Django and MySql
Note: Switch to root in the terminal and do the following:
 
$ sudo apt-get install python-django
$ sudo apt-get install mysql-server
$ sudo apt-get install python-mysqldb
MySql database and use Set up:
Note, use the password you entered when installing MySql

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE django_db;
Query OK, 1 row affected (0.01 sec)

mysql> GRANT ALL ON django_db.* TO 'djangouser'@'localhost' IDENTIFIED BY 'mypassword';
Query OK, 0 rows affected (0.03 sec)

mysql> quit
Bye
Create a Django Project
$ django-admin startproject mysite
Edit the Django database settings
Edit mysite/settings.py:
DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
DATABASE_NAME = 'django_db'             # Or path to database file if using sqlite3.
DATABASE_USER = 'djangouser'             # Not used with sqlite3.
DATABASE_PASSWORD = 'mypassword'         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
Use Django to create the database tables
$ cd mysite
$ python manage.py syncdb
Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
Creating table django_content_type
Creating table django_session
Creating table django_site

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'sofeng'):    
E-mail address: sofeng@email.com
Password: 
Password (again): 
Superuser created successfully.
Installing index for auth.Message model
Installing index for auth.Permission model
Loading 'initial_data' fixtures...
No fixtures found.
Run the development server
$ python manage.py runserver
Validating models...
0 errors found.

Django version 0.96.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[30/Jul/2008 16:37:23] "GET / HTTP/1.1" 404 2053
Point your browser at http://127.0.0.1:8000 and you should see the Django It worked! page.

one more online source: Baby Steps with Django - part 2 database setup

Friday, August 17, 2012

Pointer

A pointer is a variable which contain the memory address. It can also points to a specific data types (like struct). Three operator are commonly  used  when dealing with pointer are,
  1. &  address operator
  2. *  de-referencing operator
  3. -> structure pointer operator

Example:
In this example you will see how pointer works. 


In the above figure you see that c is a variable of char data-type and it has value "A" inside. The address of variable c is 0X3000


Now in this figure you see that c is a variable of char data-type and it has value 'A' inside. The address variable c is 0X3000. And a pointer variable cptr of char data-type. The cptr pointer variable having the address of c variable rather value. So this is one the important difference between a general variable and pointer variable is that a pointer variable contains memory address.

A Programatic example

#include <stdio.h>
void main()
{
char c ='A';
char *cptr;
cptr=&c;
printf("\n Value of c is: %c",c);
printf("\n The address of &c is: %p",&c);
printf("\n The address of &cptr is: %p",&cptr);
printf("\n Value of cptr is: %p",cptr);
printf("\n Access variable which *cptr point to is: %c",*cptr);
printf("\n-----------------------------------------------------\n");
}


----------------------------------------------------------------------
Output
----------------------------------------------------------------------
Value of c is: A
The address of &c is: 0xbfe8447f
The address of &cptr is: 0xbfe84478
Value of cptr is: 0xbfe8447f
Access variable which *cptr point to is: A
----------------------------------------------------------------------

 










Thursday, February 16, 2012

How Web server works?

This post describes "how web server works".

1. Introduction:
All of you may have question that how and what mechanisms are involved in the Internet. Finally we are receiving our interested information as web-pages with ease of simple efforts (typing context in the search engine). We used to sit in front of computer, right now, viewing this page in a browser. So, when you clicked on the link or typed in its URL for this page, what happened behind the scenes to bring this page onto your screen?
If you've ever been curious about the process, or have ever wanted to know some of the specific mechanisms that allow you to surf the Internet, then read on. In this article, you will learn how Web servers bring pages into your computer-screen-browser (home, school or office). Let's get started!

2.  Process while typing URL in browser:
The steps involved with browser while typing URL in address bar of browser. For example let us take an illustrative url link, as, www.en.wikipedia.org/wiki/Stephen_Hawking. (I considered this URL since, I am curious about his ideology).

The browser decouple the URL into three parts are,
  1. The protocol ("http")
  2. The server name ("www.en.wikipedia.org")
  3. The file name ("wiki/Stephen_Hawking")
Using this information, the browser should get the exact location of the server name( point #2). There fore, the browser communicated with a name server using "http" protocol for obtaining the location of the server name  "www.en.wikipedia.org". Typically, in Internet domain the location will be described with IP Address. There for finally the browser gets the ip address of the server machine. The browser then form a connection to the server located at the IP address on port 80.
 Now, the browser sent a GET request to the server via the HTTP protocol, asking for the file "www.en.wikipedia.org/wiki/Stephen_Hawking" (Note that cookies may be sent from browser to server with the GET request).
The server then sent the HTML file to the browser, namely web-page. (Cookies may also be sent from server to browser at the header for the page.) The browser translates the HTML tags and display on the screen.
Note:
If you find all computer jargons included in this process are new, start to learn web and its associated technologies. The best place to get to know about web-technologies is here. And to understand this whole process in comprehensive details, you need to learn and start with IP addresses, ports, protocols and keep go on.


The next process will be updated soon.