赞
踩
在settings.py中
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘sqlname’,
‘USER’: ‘user_name’,
‘PASSWORD’: ‘password’,
‘HOST’: ‘192.168.14.24’,
‘PORT’: ‘3306’,
}
}
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
SESSION_COOKIE_AGE=60*60*60
//此中间件一般注释掉
# ‘django.middleware.csrf.CsrfViewMiddleware’,
在命令窗口
django-admin startapp 应用名
在settings.py
中激活应用
INSTALLED_APPS = [
… ,
‘用户名’,
]
在项目路由中,配置 应用路由
url(’^user/’, include(‘user.urls’))
pip install django -i http://pypi.douban.com/simple/
pip install mysqlclient
python manage.py createsuperuser
http://127.0.0.1:8000/admin/
from django.contrib import admin
from . import models
class StudentAdmin(admin.ModelAdmin):
list_display = ("name", "sex" , "stuNo", "birth")
admin.site.register(models.Student, StudentAdmin)
settings.py
中,添加一个 本地化中间件MIDDLEWARE = [
...
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
...
]
class Student(models.Model):
....
class Meta:
db_table = "t_student"
verbose_name = "学生"
verbose_name_plural = "学生信息"
class Student(models.Model):
...
class Meta:
ordering = ["-id"] # 代表根据 id属性进行降序排列
=================================================================================
python manage.py createsuperuser
http://127.0.0.1:8000/admin/
from django.contrib import admin
from . import models
class StudentAdmin(admin.ModelAdmin):
list_display = ("name", "sex" , "stuNo", "birth")
admin.site.register(models.Student, StudentAdmin)
settings.py
中,添加一个 本地化中间件MIDDLEWARE = [
...
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
...
]
class Student(models.Model):
....
class Meta:
db_table = "t_student"
verbose_name = "学生"
verbose_name_plural = "学生信息"
class Student(models.Model):
...
class Meta:
ordering = ["-id"] # 代表根据 id属性进行降序排列
class StudentAdmin(admin.ModelAdmin):
search_fields = ("属性", "属性", ...)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。