΢ Ͷ ^ ھ

cba广州队赛程 :django ļςܵPa(׶)

cba㶫 www.axwwg.com  •rg2020-01-26 12:00:40   ߣ   ҪuՓ(0)

һ½Ŀļ޸ƒݣ


ALLOWED_HOSTS = ['127.0.0.1','localhost']
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
STATICFILES_DIRS = [

һ½Ŀļ޸ƒݣ

ALLOWED_HOSTS = ['127.0.0.1','localhost']
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), MEDIA_ROOT]

ԓĿ½һc manage.py ͬĿļĿmedia
mediaļA½һĿςļıλ@ҰԓĿheadpicsģMÑx^ļ

½APP@ҰԓappuploadFile

app

python manage.py startapp uploadFile

uploadFileµmodels.pyļճN´a

from django.db import models

class User(models.Model):
 name = models.CharField(max_length=12)
 file = models.FileField(upload_to='headpics')

Ҫļ INSTALLED_APPS бעԓapp

Ȼڿ_

python manage.py makemigrations uploadFile
python manage.py migrate uploadFile

·

·?ϒȿz´?/p>

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
 path('admin/', admin.site.urls),
 path('index/',include("uploadFile.urls")),
]

admin pycharmԄӵҪԒԄhȥ


ȻuploadFile½urls.py??·

ڶ·ճN´a

from django.urls import path
from . import views

app_name = 'upload'
urlpatterns = [
 path('file/',views.userfile,name='userfile'),
 path('file/detail/',views.detailFile,name='delfile'),
]

ҕD

uploadFileviews.pyļճN´a

from django.shortcuts import render,get_object_or_404
from django.http import HttpResponse
import uuid,os
from .models import User
# Create your views here.
def userfile(request):
 return render(request,'uploadFile/uploadFile.html')
def detailFile(request):
 if request.method == "POST":
  name = request.POST.get('name')
  file = request.FILES.get('file',None)
  if not file:
   return HttpResponse("<p>߀δς^</p>")
  file.name = getUUID(file.name)
  user = User.objects.create(name=name, file=file)
  with open(os.path.join("D:\\upload",file.name),'wb+') as relfile:
   for crunk in file.chunks():
    relfile.write(crunk)
  return HttpResponse("<p>ςɹ</p>")
 else:
  pass
def getUUID(filename):
 id = str(uuid.uuid4())
 extend = os.path.splitext(filename)[1]
 return id+extend

ģ

uploadFile½һtemplatesĿԓĿ½һuploadFileĿԓĿ½һuploadFilehtmlļ

ԓhtmlļճN´a

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>upload</title>
</head>
<body>
 <form action="{% url 'upload:delfile' %}" method="post" enctype="multipart/form-data">
  {% csrf_token %}
  ǷQ <input type="text" name="name"><br><br>
  ^ :  <input type="file" name="file"><br><br>
  <input type="submit" value="ύ">
 </form>
</body>
</html>

󹦸

\֮ڞg[ ݔ //127.0.0.1:8000/index/file/ ԿЧ£

ݔ֮cύ͕rڔ^Ҫӛڔ file ֶα䌍ļ·Ϣһַ

ͬrԓļҲڄńuploadļA

ԇLԇӸύɹ֮󷵻һЧ

Y

СoҽBdjango ļςܵPaϣ

ܸdȤ:

  • python+djangoٌFļς
  • Python+djangoFεļς
  • PythonDjangoЌļςţƴ惦Ĵa
  • Python+djangoFļς

P

  • django ļςܵPa(׶)

    django ļςܵPa(׶)

    һ½Ŀļ޸ƒݣ ALLOWED_HOSTS = ['127.0.0.1','localhost'] MEDIA_ROOT = os.path.join(BASE_DIR,'media') STATICFILES_DIRS = [
    2020-01-26
  • ʹtensorflow DataSetFЧd׃Lıݔ

    ʹtensorflow DataSetFЧd׃Lıݔ

    DataSettensorflow 1.3汾Ƴһhigh-levelapi1.3汾߀ֻ̎ڜyԇA1.4汾ѽʽƳ ھWһlFPʹDataSetdıY
    2020-01-26
  • \ՄtensorflowDatasetDƬxȡSȵIJԔ

    \ՄtensorflowDatasetDƬxȡSȵIJԔ

    SxȡDƬw, h, c: import tensorflow as tf import glob import os def _parse_function(filename): # print(filename) image_string = tf.r
    2020-01-26
  • tensorflowʹrange_input_producerྀxȡ

    tensorflowʹrange_input_producerྀxȡ

    ȷPIa i = tf.train.range_input_producer(NUM_EXPOCHES, num_epochs=1, shuffle=False).dequeue() inputs = tf.slice(array, [i * BATCH_SIZE], [BATCH
    2020-01-26
  • Ptf.reverse_sequence()

    Ptf.reverse_sequence()

    tf.reverse_sequence() ڿbidirectional_dynamic_rnn()Դaĕr˴a{ reverse_sequence()@һֻȥ@÷lF
    2020-01-26
  • pRNN:bidirectional_dynamic_rnn()ʹԔ

    pRNN:bidirectional_dynamic_rnn()ʹԔ

    pRNNbidirectional_dynamic_rnn()ʹԔ fžʲôҪʹõpRNNxһƪµĕrᵽϢʮֵҪ@ЩϢDzԲ׽
    2020-01-26
  • Ptf.nn.dynamic_rnnֵԔ

    Ptf.nn.dynamic_rnnֵԔ

    ԭ tf.nn.dynamic_rnn( cell, inputs, sequence_length=None, initial_state=None, dtype=None, parallel_iterations=None, swap_memory=Fal
    2020-01-26
  • pythonCWxgboostʹ

    pythonCWxgboostʹ

    1.xȡ ԭxgboostxȡlibsvm import xgboost as xgb data = xgb.DMatrix(libsvmļ) ʹsklearnxȡlibsvm from sklearn.
    2020-01-26
  • \ՄTensorflow ӑBpRNNݔ}

    \ՄTensorflow ӑBpRNNݔ}

    tf.nn.bidirectional_dynamic_rnn() def bidirectional_dynamic_rnn( cell_fw, # ǰRNN cell_bw, # RNN inputs, # ݔ sequence_length=No
    2020-01-26
  • pythonȡվӕϢČFa

    pythonȡվӕϢČFa

    TxֻץȡQϢdַ惦 칤DBUtil.py import pymysql class DBUtils(object): def connDB(self):
    2020-01-26