1, this upload method is done with the admin background, with the database and model to do
Vim settings.py
Media_root = '/headimg/' file is saved in the path (and later)
# ' Django.middleware.csrf.CsrfViewMiddleware ', ban this, cross the station without problems
' Django.contrib.admin ', open this, admin is available
' ENGINE ': ' Django.db.backends.sqlite3 ', select Sqlite3 database
2. Vim blog/models.py
From django.db import Models
Class User (models. Model):
Username = models. Charfield (max_length=30)
Headimg = models. Filefield (upload_to= './upload/') Total path:/headimg/upload/
def __unicode__ (self):
Return Self.username
3. Vim urls.py
From Django.contrib Import Admin Open these two, admin with it (note indent!!!) Remember, my pain)
Admin.autodiscover ()
URL (r ' ^admin/', include (Admin.site.urls)), open this
URL (r ' ^blog/register/$ ', ' Blog.views.register '), which was written by myself
4. Python manage.py syncdb
Log in to the Web page to create a user and upload files and then find it under/headimg/upload/.
The command line display is:
Sqlite3 my.db
SELECT * FROM Blog_user
Django Learning -14 Django File Upload (admin background)