parent
847c59aa43
commit
bf9a342df4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CliConfig(AppConfig):
|
||||
name = 'cli'
|
||||
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
]
|
||||
@ -0,0 +1,5 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
|
||||
def index(request):
|
||||
return render(request, 'cli.html')
|
||||
@ -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)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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
|
||||
@ -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/'
|
||||
@ -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')),
|
||||
]
|
||||
@ -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")
|
||||
@ -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()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PollsConfig(AppConfig):
|
||||
name = 'polls'
|
||||
@ -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'),
|
||||
),
|
||||
]
|
||||
@ -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),
|
||||
),
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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
|
||||
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
]
|
||||
@ -0,0 +1,5 @@
|
||||
from django.http import HttpResponse
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("Hello, world.")
|
||||
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CLI</title>
|
||||
</head>
|
||||
<body>
|
||||
CLI
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Hello</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ hello }}</h1>
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,196 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Vue-upload-component Test</title>
|
||||
<script src="https://unpkg.com/vue"></script>
|
||||
<script src="https://unpkg.com/vue-upload-component"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
|
||||
<div class="example-multiple">
|
||||
<h1 id="example-title" class="example-title">Multiple instances</h1>
|
||||
<div class="upload">
|
||||
<ul>
|
||||
<li v-for="(file, index) in files1" :key="file.id">
|
||||
<span>{{ file.name }}</span> -
|
||||
<span v-if="file.error">{{ file.error }}</span>
|
||||
<span v-else-if="file.success">success</span>
|
||||
<span v-else-if="file.active">active</span>
|
||||
<span v-else-if="file.active">active</span>
|
||||
<span v-else></span>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="example-btn">
|
||||
<file-upload
|
||||
class="btn btn-primary"
|
||||
input-id="file1"
|
||||
post-action="http://localhost:8000/upload"
|
||||
v-model="files1"
|
||||
ref="upload1"
|
||||
@input-file="inputFile"
|
||||
@input-filter="inputFilter"
|
||||
>
|
||||
<i class="fa fa-plus"></i>
|
||||
Select files
|
||||
</file-upload>
|
||||
<label for="file1" class="btn btn-primary">Label Select files</label>
|
||||
<button type="button" id="button1" class="btn btn-success"
|
||||
v-if="!$refs.upload1 || !$refs.upload1.active" @click.prevent="$refs.upload1.active = true">
|
||||
<i class="fa fa-arrow-up" aria-hidden="true"></i>
|
||||
Start Upload
|
||||
<img :src="img1" alt="">
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger" v-else @click.prevent="$refs.upload1.active = false">
|
||||
<i class="fa fa-stop" aria-hidden="true"></i>
|
||||
Stop Upload
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="upload">
|
||||
<ul>
|
||||
<li v-for="(file, index) in files2" :key="file.id">
|
||||
<span>{{ file.name }}</span> -
|
||||
<span v-if="file.error">{{ file.error }}</span>
|
||||
<span v-else-if="file.success">success</span>
|
||||
<span v-else-if="file.active">active</span>
|
||||
<span v-else-if="file.active">active</span>
|
||||
<span v-else></span>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="example-btn">
|
||||
<file-upload
|
||||
class="btn btn-primary"
|
||||
|
||||
input-id="file2"
|
||||
post-action="upload"
|
||||
v-model="files2"
|
||||
ref="upload2"
|
||||
@input-file="inputFile"
|
||||
@input-filter="inputFilter">
|
||||
<i class="fa fa-plus"></i>
|
||||
Select files
|
||||
<img :src="img2" alt="">
|
||||
</file-upload>
|
||||
<label for="file2" class="btn btn-primary">Label Select files</label>
|
||||
<button type="button" class="btn btn-success" v-if="!$refs.upload2 || !$refs.upload2.active"
|
||||
@click.prevent="$refs.upload2.active = true">
|
||||
<i class="fa fa-arrow-up" aria-hidden="true"></i>
|
||||
Start Upload
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger" v-else @click.prevent="$refs.upload2.active = false">
|
||||
<i class="fa fa-stop" aria-hidden="true"></i>
|
||||
Stop Upload
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data: function () {
|
||||
return {
|
||||
files1: [],
|
||||
files2: [],
|
||||
img1: null,
|
||||
img2: null,
|
||||
|
||||
isWatch: false,
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
console.log('mounted...');
|
||||
//console.log(this.img3)
|
||||
|
||||
this.isWatch = true;
|
||||
this.isWatch = false
|
||||
|
||||
},
|
||||
computed: {
|
||||
img3: function () {
|
||||
console.log('compute...')
|
||||
return 'img_3.0'
|
||||
}
|
||||
},
|
||||
components: {
|
||||
FileUpload: VueUploadComponent
|
||||
},
|
||||
watch: {
|
||||
files1: function () {
|
||||
},
|
||||
files2: function () {
|
||||
},
|
||||
|
||||
isWatch: {
|
||||
immediate: false,
|
||||
handler: function (value) {
|
||||
console.log('is watch')
|
||||
console.log('watch value:', value);
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
/**
|
||||
* Has changed
|
||||
* @param Object|undefined newFile 只读
|
||||
* @param Object|undefined oldFile 只读
|
||||
* @return undefined
|
||||
*/
|
||||
inputFile: function (newFile, oldFile) {
|
||||
if (newFile && oldFile && !newFile.active && oldFile.active) {
|
||||
// 获得相应数据
|
||||
console.log('response', newFile.response)
|
||||
if (newFile.xhr) {
|
||||
// 获得响应状态码
|
||||
|
||||
console.log('status', newFile.xhr.status)
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Pretreatment
|
||||
* @param Object|undefined newFile 读写
|
||||
* @param Object|undefined oldFile 只读
|
||||
* @param Function prevent 阻止回调
|
||||
* @return undefined
|
||||
*/
|
||||
inputFilter: function (newFile, oldFile, prevent) {
|
||||
|
||||
if (newFile && !oldFile) {
|
||||
// 过滤不是图片后缀的文件
|
||||
if (!/\.(jpeg|jpe|jpg|gif|png|webp)$/i.test(newFile.name)) {
|
||||
return prevent()
|
||||
}
|
||||
}
|
||||
|
||||
// 创建 blob 字段 用于图片预览
|
||||
newFile.blob = ''
|
||||
let URL = window.URL || window.webkitURL
|
||||
if (URL && URL.createObjectURL) {
|
||||
newFile.blob = URL.createObjectURL(newFile.file)
|
||||
}
|
||||
|
||||
// 自动上传
|
||||
if (Boolean(newFile) !== Boolean(oldFile) || oldFile.error !== newFile.error) {
|
||||
if (!this.$refs.upload1.active) {
|
||||
console.log('auto start...')
|
||||
this.$nextTick(function () {
|
||||
this.$refs.upload1.active = true;
|
||||
this.$refs.upload2.active = true;
|
||||
});
|
||||
console.log(this.$refs.upload1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in new issue