Django Learning -14 Django File Upload (admin background)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.