Commit e9b69800 authored by root's avatar root


from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class AppConfig(AppConfig):
name = 'app'
from import BaseCommand
from django.contrib.auth.models import User
import os
class Command(BaseCommand):
help = 'Create admin & guest user'
def handle(self, *args, **options):
def create_user(name, password=None):
user = User.objects.create_user(name,
password=os.urandom(1024) if password is None else password)
user.is_superuser = False
user.is_staff = False
create_user("guest", "guest")
\ No newline at end of file
from django.db import models
# Create your models here.
<!DOCTYPE html>
<html lang="zh">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{% block title %}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="content container pt-5">
{% block content %}
{% endblock %}
\ No newline at end of file
{% extends "app/base.html" %}
{% block title %}{{ name }}{% endblock %}
{% block content %}
<h1>{{ name }}</h1>
<form method="post" action=".">
<div class="form-group">
用户名:<input type="text" class="form-control" name="username">
<div class="form-group">
密码:<input type="password" class="form-control" name="password">
<button type="submit" class="btn btn-primary">登录</button>
<p>你可以使用 guest 用户(密码为 guest)体验。</p>
{% endblock %}
\ No newline at end of file
{% extends "app/base.html" %}
{% block title %}{{ name }} - 个人信息 {% endblock %}
{% block content %}
<h1>{{ name }} - 个人信息</h1>
<h3>欢迎您,{{ username }}!</h3>
<p>{{ profile }}</p>
<p><a class="btn btn-danger" href="{% url 'logout' %}">退出账户</a></p>
<h4>Debug - Your cookie</h4>
<p id="cookie"></p>
document.getElementById("cookie").textContent = document.cookie;
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('profile', views.profile, name='profile'),
path('logout', views.log_out, name='logout')
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt
name = "Rabbit House 成员管理系统"
def index(request):
if request.method == "GET":
if request.user.is_authenticated:
return redirect(reverse("profile"))
return render(request, 'app/index.html', {
"name": name
elif request.method == "POST":
username = request.POST["username"]
password = request.POST["password"]
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect(reverse("profile"))
return redirect(reverse("index"))
def profile(request):
if request.user.username == "admin":
user_profile = "flag redacted. login as admin on server to get flag."
user_profile = "仅 admin 用户可阅览 flag。"
return render(request, 'app/profile.html', {
"name": name,
"username": request.user,
"profile": user_profile
def log_out(request):
return redirect(reverse("index"))
from django.contrib.auth import models
def update_last_login(sender, user, **kwargs):
models.update_last_login = update_last_login
File added
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openlug.settings')
from import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
if __name__ == '__main__':
Django settings for openlug project.
Generated by 'django-admin startproject' using Django 2.2.5.
For more information on this file, see
For the full list of settings and their values, see
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
# SECURITY WARNING: keep the secret key used in production non-secret!
SECRET_KEY = 'd7um#o19q+v24!vkgzrxme41wz5#_h0#[email protected]&uwe39'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
# Application definition
# 'django.contrib.admin',
# we're going to be RESTful in the future,
# to prevent inconvenience, just turn csrf off.
# 'django.middleware.csrf.CsrfViewMiddleware',
ROOT_URLCONF = 'openlug.urls'
# for database performance
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
# javascript code can get document.cookie, debug
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'context_processors': [
WSGI_APPLICATION = 'openlug.wsgi.application'
# Database
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# Password validation
'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
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
"""openlug URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
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.urls import path, include
urlpatterns = [
# path('admin/',,
path('', include('app.urls')),
WSGI config for openlug project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openlug.settings')
application = get_wsgi_application()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment