$django-admin.py startproject web2$cd web2/$python manage.py startapp blog$vim web2
Note settings.py The following two sections, the first to configure the database, followed by the Installed_app to add the new app
DATABASES = { 'default': { 'ENGINE':'Django.db.backends.mysql',#Add ' postgresql_psycopg2 ', ' MySQL ', ' sqlite3 ' o 'NAME':'DJ_DB01',#Or Path to database file if using Sqlite3. #The following settings is not used with Sqlite3: 'USER':'Root', 'PASSWORD':"', 'HOST':'localhost',#Empty for localhost through domain sockets 'PORT':"',#Set to empty string for default. } }
Installed_apps = ( 'Django.contrib.auth', 'Django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'Django.contrib.staticfiles', 'Blog', #uncomment the next line to enable the admin: 'Django.contrib.admin', #uncomment the next line to enable admin documentation: 'Django.contrib.admindocs',)
Next Edit models.py
$vim blog/models.py
from Import Models
In MySQL, the corresponding data is created.
Mysql> CREATE DATABASE dj_db01 default CharSet UTF8;
You can now automatically generate various tables.
$ python manage.py syncdb
Now edit the config for the following URL
$vim web1/urls.py
fromDjango.conf.urlsImportpatterns, include, url#uncomment the next lines to enable the admin:#From django.contrib Import admin#Admin.autodiscover ()Urlpatterns= Patterns ("', #Examples: #URL (r ' ^$ ', ' web1.views.home ', name= ' home '), #URL (r ' ^web1/', include (' Web1.foo.urls ')), #Uncomment the Admin/doc line below to enable admin documentation: #URL (r ' ^admin/doc/', include (' Django.contrib.admindocs.urls ')), #uncomment the next line to enable the admin: #URL (r ' ^admin/', include (Admin.site.urls)),URL (r'^blog/$','Blog.views.index'),)
$mkdir blog/static/images
and copy it from somewhere else, and here I copy the img2.jpg.
Next Edit the page
$mkdir blog/Templates$vim Blog/templates/index.html
/static/images/img2.jpg'/>
Run for a minute
Python manage.py runserver 3900