diff --git a/__pycache__/manage.cpython-37.pyc b/__pycache__/manage.cpython-37.pyc new file mode 100644 index 0000000..b9dff5e Binary files /dev/null and b/__pycache__/manage.cpython-37.pyc differ diff --git a/cli/__init__.py b/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cli/__pycache__/__init__.cpython-37.pyc b/cli/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..3fd9728 Binary files /dev/null and b/cli/__pycache__/__init__.cpython-37.pyc differ diff --git a/cli/__pycache__/urls.cpython-37.pyc b/cli/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..dd2e747 Binary files /dev/null and b/cli/__pycache__/urls.cpython-37.pyc differ diff --git a/cli/__pycache__/views.cpython-37.pyc b/cli/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..e053d68 Binary files /dev/null and b/cli/__pycache__/views.cpython-37.pyc differ diff --git a/cli/admin.py b/cli/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/cli/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/cli/apps.py b/cli/apps.py new file mode 100644 index 0000000..5298e25 --- /dev/null +++ b/cli/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CliConfig(AppConfig): + name = 'cli' diff --git a/cli/migrations/__init__.py b/cli/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cli/models.py b/cli/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/cli/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/cli/tests.py b/cli/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/cli/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/cli/urls.py b/cli/urls.py new file mode 100644 index 0000000..c486297 --- /dev/null +++ b/cli/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] \ No newline at end of file diff --git a/cli/views.py b/cli/views.py new file mode 100644 index 0000000..ab2cc79 --- /dev/null +++ b/cli/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + + +def index(request): + return render(request, 'cli.html') diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..390c767 --- /dev/null +++ b/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') + try: + from django.core.management 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 + execute_from_command_line(sys.argv) diff --git a/mysite/__init__.py b/mysite/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mysite/__pycache__/__init__.cpython-37.pyc b/mysite/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..f8a6236 Binary files /dev/null and b/mysite/__pycache__/__init__.cpython-37.pyc differ diff --git a/mysite/__pycache__/middlewares.cpython-37.pyc b/mysite/__pycache__/middlewares.cpython-37.pyc new file mode 100644 index 0000000..0e1ab3b Binary files /dev/null and b/mysite/__pycache__/middlewares.cpython-37.pyc differ diff --git a/mysite/__pycache__/settings.cpython-37.pyc b/mysite/__pycache__/settings.cpython-37.pyc new file mode 100644 index 0000000..1723d6b Binary files /dev/null and b/mysite/__pycache__/settings.cpython-37.pyc differ diff --git a/mysite/__pycache__/urls.cpython-37.pyc b/mysite/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..c019960 Binary files /dev/null and b/mysite/__pycache__/urls.cpython-37.pyc differ diff --git a/mysite/__pycache__/views.cpython-37.pyc b/mysite/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..dfca686 Binary files /dev/null and b/mysite/__pycache__/views.cpython-37.pyc differ diff --git a/mysite/__pycache__/wsgi.cpython-37.pyc b/mysite/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 0000000..1c1e733 Binary files /dev/null and b/mysite/__pycache__/wsgi.cpython-37.pyc differ diff --git a/mysite/middlewares.py b/mysite/middlewares.py new file mode 100644 index 0000000..c510a83 --- /dev/null +++ b/mysite/middlewares.py @@ -0,0 +1,7 @@ +from django.utils.deprecation import MiddlewareMixin + + +class AllowCORS(MiddlewareMixin): + def process_response(self, request, response): + response['Access-Control-Allow-Origin'] = '*' + return response diff --git a/mysite/settings.py b/mysite/settings.py new file mode 100644 index 0000000..6778391 --- /dev/null +++ b/mysite/settings.py @@ -0,0 +1,118 @@ +""" +Django settings for mysite project. + +Generated by 'django-admin startproject' using Django 2.1.5. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/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.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'sndhvl5)$2l9vyl@flwxctl65ss#-(s&g80x4vzcpq@=f-o&+e' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + +# Application definition + +INSTALLED_APPS = [ + 'polls.apps.PollsConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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', + 'mysite.middlewares.AllowCORS', +] + +ROOT_URLCONF = 'mysite.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + BASE_DIR + '/templates', + ], + '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 = 'mysite.wsgi.application' + +# Database +# https://docs.djangoproject.com/en/2.1/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.1/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.1/topics/i18n/ + +LANGUAGE_CODE = 'zh-hans' + +TIME_ZONE = 'Asia/Shanghai' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/mysite/urls.py b/mysite/urls.py new file mode 100644 index 0000000..1947c35 --- /dev/null +++ b/mysite/urls.py @@ -0,0 +1,28 @@ +"""mysite URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.1/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.urls import include, path +from . import views + +urlpatterns = [ + path('polls/', include('polls.urls')), + path('admin/', admin.site.urls), + path('', views.hello, name='hello'), + path('api', views.api), + path('upload', views.upload), + path('post', views.post), + path('cli', include('cli.urls')), +] diff --git a/mysite/views.py b/mysite/views.py new file mode 100644 index 0000000..4252716 --- /dev/null +++ b/mysite/views.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +import json +from django.shortcuts import render +from django.http import HttpResponse + + +def hello(request): + print(request.GET.get('name')) + context = {'hello': '!Hello World!'} + return render(request, 'hello.html', context) + + +def post(request): + return render(request, 'index.html') + + +def upload(request): + files = request.FILES + print(files) + return HttpResponse(json.dumps({"success": "success"}), content_type="application/json") + + +def api(request): + print(request.POST.get('name')) + response = { + 'status': 1, + 'info': 'message from python', + 'msg': 'message from python', + 'data': [{ + 'name': 'a'}, + {'name': 'b'}, + {'name': 'c'} + ]} + return HttpResponse(json.dumps(response), content_type="application/json") diff --git a/mysite/wsgi.py b/mysite/wsgi.py new file mode 100644 index 0000000..77f71eb --- /dev/null +++ b/mysite/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for mysite project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') + +application = get_wsgi_application() diff --git a/polls/__init__.py b/polls/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/polls/__pycache__/__init__.cpython-37.pyc b/polls/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..1e33a7b Binary files /dev/null and b/polls/__pycache__/__init__.cpython-37.pyc differ diff --git a/polls/__pycache__/admin.cpython-37.pyc b/polls/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000..287dea2 Binary files /dev/null and b/polls/__pycache__/admin.cpython-37.pyc differ diff --git a/polls/__pycache__/apps.cpython-37.pyc b/polls/__pycache__/apps.cpython-37.pyc new file mode 100644 index 0000000..3bdac30 Binary files /dev/null and b/polls/__pycache__/apps.cpython-37.pyc differ diff --git a/polls/__pycache__/models.cpython-37.pyc b/polls/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..cbc9fe0 Binary files /dev/null and b/polls/__pycache__/models.cpython-37.pyc differ diff --git a/polls/__pycache__/urls.cpython-37.pyc b/polls/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..be1d8f7 Binary files /dev/null and b/polls/__pycache__/urls.cpython-37.pyc differ diff --git a/polls/__pycache__/views.cpython-37.pyc b/polls/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..7ff66e9 Binary files /dev/null and b/polls/__pycache__/views.cpython-37.pyc differ diff --git a/polls/admin.py b/polls/admin.py new file mode 100644 index 0000000..9d78553 --- /dev/null +++ b/polls/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin + +# Register your models here. +from django.contrib import admin + +from .models import Question + +admin.site.register(Question) \ No newline at end of file diff --git a/polls/apps.py b/polls/apps.py new file mode 100644 index 0000000..d0f109e --- /dev/null +++ b/polls/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PollsConfig(AppConfig): + name = 'polls' diff --git a/polls/migrations/0001_initial.py b/polls/migrations/0001_initial.py new file mode 100644 index 0000000..4be8d30 --- /dev/null +++ b/polls/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# Generated by Django 2.1.5 on 2019-01-30 08:24 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Choice', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('choice_text', models.CharField(max_length=200)), + ('votes', models.IntegerField(default=0)), + ], + ), + migrations.CreateModel( + name='Question', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('question_text', models.CharField(max_length=200)), + ('pub_date', models.DateTimeField(verbose_name='date published')), + ], + ), + migrations.AddField( + model_name='choice', + name='question', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question'), + ), + ] diff --git a/polls/migrations/0002_auto_20190130_1708.py b/polls/migrations/0002_auto_20190130_1708.py new file mode 100644 index 0000000..d4a9d04 --- /dev/null +++ b/polls/migrations/0002_auto_20190130_1708.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2019-01-30 09:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('polls', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='question', + name='question_text', + field=models.CharField(max_length=50), + ), + ] diff --git a/polls/migrations/__init__.py b/polls/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/polls/migrations/__pycache__/0001_initial.cpython-37.pyc b/polls/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 0000000..a085078 Binary files /dev/null and b/polls/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/polls/migrations/__pycache__/0002_auto_20190130_1708.cpython-37.pyc b/polls/migrations/__pycache__/0002_auto_20190130_1708.cpython-37.pyc new file mode 100644 index 0000000..1378b8a Binary files /dev/null and b/polls/migrations/__pycache__/0002_auto_20190130_1708.cpython-37.pyc differ diff --git a/polls/migrations/__pycache__/__init__.cpython-37.pyc b/polls/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..f6a7215 Binary files /dev/null and b/polls/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/polls/models.py b/polls/models.py new file mode 100644 index 0000000..86e2d4f --- /dev/null +++ b/polls/models.py @@ -0,0 +1,23 @@ +import datetime +from django.db import models +from django.utils import timezone + + +class Question(models.Model): + question_text = models.CharField(max_length=50) + pub_date = models.DateTimeField('date published') + + def __str__(self): + return self.question_text + + def was_published_recently(self): + return self.pub_date >= timezone.now() - datetime.timedelta(days=1) + + +class Choice(models.Model): + question = models.ForeignKey(Question, on_delete=models.CASCADE) + choice_text = models.CharField(max_length=200) + votes = models.IntegerField(default=0) + + def __str__(self): + return self.choice_text diff --git a/polls/tests.py b/polls/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/polls/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/polls/urls.py b/polls/urls.py new file mode 100644 index 0000000..c486297 --- /dev/null +++ b/polls/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] \ No newline at end of file diff --git a/polls/views.py b/polls/views.py new file mode 100644 index 0000000..46e3438 --- /dev/null +++ b/polls/views.py @@ -0,0 +1,5 @@ +from django.http import HttpResponse + + +def index(request): + return HttpResponse("Hello, world.") diff --git a/templates/cli.html b/templates/cli.html new file mode 100644 index 0000000..e1b332d --- /dev/null +++ b/templates/cli.html @@ -0,0 +1,10 @@ + + +
+ +