python-Django显示登陆首页

我爱海鲸 2021-03-21 01:58:20 python

简介显示登陆首页

1、在相应目录下cmd

django-admin startproject DjangoTestLogin

使用pycharm打开项目

2、在pycharm命令行中输入命令创建相应的应用包:

python manage.py startapp stu

如图:

undefined

3、在setting.py中的INSTALLED_APPS列表中添加刚刚添加的stu应用包,如图:

undefined

4、在setting中TEMPLATES列表中添加:'DIRS': ["%s/%s" %(BASE_DIR,'templates'),],如图:

undefined

5、在根目录包的urls.py中添加:

from django.conf.urls import url, include

from django.contrib import admin



urlpatterns = [

    url(r'^admin/', admin.site.urls),

    url(r'^student/', include('stu.urls'))

]

如图:

undefined

6、在stu的urls.py中添加:

#coding=utf-8



from django.conf.urls import url

from stu import views


urlpatterns=[

    url(r'^$',views.login_view)

]

如图:


undefined

7、在stu中的views.py添加:


from django.shortcuts import render


# Create your views here.

def login_view(request):


    return render(request,'login.html')

如图:

undefined

8、创建templates文件夹并依赖项目,如图:

undefined

9、编写静态文件并复制到templates中,如图:

undefined

10、启动项目,并访问:http://127.0.0.1:8000/student/,成功,如图:

undefined

你好:我的2025