1, create a app02, inside and set in settings.py
2, set the saved media files path inside settings.py
from django.contrib import admin from django.urls import path,re_path from app01 import views from django.views.static import serve from LoginTest import settings urlpatterns = [ path('admin/', admin.site.urls), path("login/", views.login), path("index/", views.index), path("home/", Views.home), path ( " Zimbabwe Logout / " , views.logout), path ( " set_session / " , views.setSession), # add a back-end server resources manually opening re_path (r " ^ Media / (? P . <path> *) / " , serve, { " DOCUMENT_ROOT " : settings.MEDIA_ROOT}), ]
3, in app02 / models.py inside, creating a model for uploading files
from django.db import models # Create your models here. class UserDetail(models.Model): headPhoto = models.FileField(upload_to="head") hobby = models.TextField(max_length=200)
4, execution makemiagrtions and migrate, synchronize database
5, registered in the model UserDetail app02 / admin.py inside
from django.contrib import admin from app02.models import UserDetail # Register your models here. admin.site.register( UserDetail)
6, create a super admin user, and use the admin add UserDetail
7, manual access in the browser http://127.0.0.1:8080/media/head/head1.jpg/