django_初级学习(1)
1.创建项目app: pyhton manage.py satartapp User
注册APP:
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'users.apps.UsersConfig', 'captcha', ]
2.添加静态文件配置:
STATICFILES_DIRS=[ os.path.join(BASE_DIR,'static'), ]
3.设置后台语言和时间
LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shanghai'
4.设置数据库为mysql
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'EDG', 'USER': 'root', 'PASSWORD': '123456', 'HOST': '127.0.0.1', 'PORT': '3306', } }
奇淫技巧
当APP较多时,创建不同的APP 后可以在每个APP下创建views.py
在和项目同名的目录下为主要的views.py 下添加 include('captcha.urls'), 在每个APP的views下可以减少部分
同名 的 views.py urlpatterns = [ url(r'captcha/',include('captcha.urls')), url(r'^users/',include('users.urls',namespace='users')), url(r'^courses/', include('courses.urls', namespace='courses')), url(r'^$',index ,name='index') ] 其他app下的views.py from django.conf.urls import url from .views import user_register,user_login,user_logout urlpatterns = [ url(r'^user_register/$',user_register,name='user_register'), url(r'^user_login/$', user_login, name='user_login'), url(r'^user_logout/$', user_logout, name='user_logout'),]