最近在联系Django,写了个小例子网页打不开,求大神指导

Posted wang517

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了最近在联系Django,写了个小例子网页打不开,求大神指导相关的知识,希望对你有一定的参考价值。

settings.py

"""
Django settings for guest project.

Generated by ‘django-admin startproject‘ using Django 2.0.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ‘bl%t7)d*tz=_ww)i^[email protected]*9azb$f%t0h2+(e!gzmtnm-+2j‘

# SECURITY WARNING: don‘t run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
‘django.contrib.admin‘,
‘django.contrib.auth‘,
‘django.contrib.contenttypes‘,
‘django.contrib.sessions‘,
‘django.contrib.messages‘,
‘django.contrib.staticfiles‘,
‘sign‘, #添加sign应用
]

MIDDLEWARE = [
‘django.middleware.security.SecurityMiddleware‘,
‘django.contrib.sessions.middleware.SessionMiddleware‘,
‘django.middleware.common.CommonMiddleware‘,
#‘django.middleware.csrf.CsrfViewMiddleware‘,
‘django.contrib.auth.middleware.AuthenticationMiddleware‘,
‘django.contrib.messages.middleware.MessageMiddleware‘,
‘django.middleware.clickjacking.XFrameOptionsMiddleware‘,
]

ROOT_URLCONF = ‘guest.urls‘

TEMPLATES = [
{
‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,
‘DIRS‘: [],
‘APP_DIRS‘: True,
‘OPTIONS‘: {
‘context_processors‘: [
‘django.template.context_processors.debug‘,
‘django.template.context_processors.request‘,
‘django.contrib.auth.context_processors.auth‘,
‘django.contrib.messages.context_processors.messages‘,
],
},
},
]

WSGI_APPLICATION = ‘guest.wsgi.application‘


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
‘default‘: {
‘ENGINE‘: ‘django.db.backends.sqlite3‘,
‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
‘NAME‘: ‘django.contrib.auth.password_validation.UserAttributeSimilarityValidator‘,
},
{
‘NAME‘: ‘django.contrib.auth.password_validation.MinimumLengthValidator‘,
},
{
‘NAME‘: ‘django.contrib.auth.password_validation.CommonPasswordValidator‘,
},
{
‘NAME‘: ‘django.contrib.auth.password_validation.NumericPasswordValidator‘,
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = ‘en-us‘

TIME_ZONE = ‘UTC‘

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, javascript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = ‘/static/‘




urls.py
"""guest URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path(‘‘, views.home, name=‘home‘)
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path(‘‘, Home.as_view(), name=‘home‘)
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path(‘blog/‘, include(‘blog.urls‘))
"""
from django.contrib import admin
from django.conf.urls import url
from django.urls import path
from sign import views #导入sign应用views文件
urlpatterns = [
#path(‘admin/‘, admin.site.urls),
#path(‘admin/$‘,views.index),#添加index/路径配置
#url(r‘^index/$‘,views.index),
url(r‘^admin/‘, admin.site.urls),#40页
url(r‘^index/$‘, views.index),
url(r‘^login_action/$‘,views.login_action),
]

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse
from django.http import HttpResponse
# Create your views here.
##
#def index(request):
#return HttpResponse("Hello Django!")
## return render(request,"index.html")
##

#登录动作
def login_action(request):
if request.method == ‘post‘:
username == request.POST.get(‘username‘,‘‘)
password == request.POST.get(‘password‘,‘‘)
if username ==‘admin‘ and password == ‘admin123‘:
return HttpResponse(‘login success!‘)
else:
return render(request,‘index.html‘,{‘error‘:‘username or password error!‘})



index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Django Page</title>
</head>
<body>
<h1>发布会管理</h1>
<form method="post" action="/login_action/">
<input name="username" type="text" placeholder="username"><br>
<input name="password" type="password" placeholder="password"><br>
{{ error }}<br>
<button id="btn" type="submit">登录</button>
{% csrf_token %}
</form>

</body>
</html>







以上是关于最近在联系Django,写了个小例子网页打不开,求大神指导的主要内容,如果未能解决你的问题,请参考以下文章

python错误,写了个小程序,if语句总是不执行,求高手指点

Edge浏览器最近啥网页都打不开,总是提示加载出现问题(未响应)

新创建django项目,但网页打不开127.0.0.1:8000

安卓谷歌浏览器打不开求原因

oracle11g EM网页打不开

网页打不开GOOGLE DRIVE