Not be convinent to Type Chinese in Fedora 20, Using English to record the process of how I create my first Django example.
1 Create Django Project
1.1 File -->New -->Project -->Pydev Django project ---> Next
type Project name and select SQList as database
1.2 Run click 'manage.py' -->Run as --> Run configurations -->Arguments
Input 'runserver 9000' in the Program arguments tab.
9000 is the port I'm using.
1.3 Create new Pydev module view.py and input the following:
from django.http import HttpResponse
from django.shortcuts import render_to_response
import mysql.connector
def hello(request):
#return HttpResponse("Hello world,My FristDJ1")
#names=['seanL','a','b','c']
cnx = mysql.connector.connect(user='root', password='xxx',
host='127.0.0.1',
database='test')
cursor = cnx.cursor()
cursor.execute('select F2 from test.xx')
names = [row[0] for row in cursor.fetchall()]
cnx.close()
return render_to_response('list.html',{'names':names})
I did three test in this page
a) using return HttpResponse("Hello world,My FristDJ1") just display a plain text
b) Create html template list.html and copy the template file to /usr...
(the error message will tell you where the template file you should paste)
c) fetch data from Mysql to display data on html.
I guess the data fetching process should be done in Module. here is doing some testof
1.4 Update urls.py
urlpatterns = patterns('',
(r'^hello/$', hello),
I encoutered some error in this step,for example:
didn't keep '' before r'^ in patterns()
didn't add 'from view import hello' (it works with out this step in my second example)