django從零開始-入門

1.建立應用 signcss

python .\manage.py startapp sign

2.運行項目html

python .\manage.py runserver

3.添加應用sign到項目  python

  1. 編輯setting文件

2.添加路由設置bootstrap

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^index$',views.index),
    
]

  3.建立index函數app

# Create your views here.
def index(request):
    return HttpResponse('你好,第一個dja

4.使用模板函數

建立登陸頁面替代HttpResponsepost

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3個meta標籤*必須*放在最前面,任何其餘內容都*必須*跟隨其後! -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Guest Login</title>

    <!-- Bootstrap core CSS -->
    <link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="//v3.bootcss.com/examples/signin/signin.css" rel="stylesheet">

  </head>

  <body>

    <div class="container">
      <form class="form-signin" method="post" action="/login_action/">
        <h2 class="form-signin-heading">Guest System</h2>
        <label for="inputUsername" class="sr-only">Username</label>
          <input name="username" type="text" id="inputUsername" class="form-control" placeholder="Username" required autofocus>
        <label for="inputPassword" class="sr-only">Password</label>
          <input name="password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
          <p style="color:red">{{error}}</p> <br>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
      </form>

    </div> <!-- /container -->

  </body>

</html>

更改index函數爲ui

# Create your views here.
def index(request):
    return render(request,'index.html')

 

 

 

ps:站點圖標連接一點要弄對 否則會報錯 我是用的是七牛圖牀this

 

效果以下url

相關文章
相關標籤/搜索