python - Django 1.8 File Upload Example -


i’m new django development platform. have been struggling create basic file upload app in django 1.8.2 (latest version). not find up-to-date example/snippet. appreciate if post here or refer me minimal complete (model, view, template) example code so.

i’ve observed many other examples online notice version not have media_root or media_url attributes default. example:

media_root = '/path/to/myproject/media/' media_url = '/media/' 

here models.py page

from django.db import models  # create models here.  class test(models.model):    first_name = models.slugfield()    last_name = models.slugfield()    email = models.emailfield()    timestamp = models.datetimefield(auto_now_add = true, auto_now = false)    updated = models.datetimefield(auto_now_add = false, auto_now = true)  def __unicode__(self):     return self.email 

here forms.py page

from django import forms .models import test  class emailform(forms.form):     first_name = forms.charfield(required=false)     last_name = forms.charfield(required=false)     email = forms.emailfield()  class testform(forms.modelform):     class meta:     model = test 

here views.py page

from django.shortcuts import render django.shortcuts import render_to_response django.template import requestcontext django.http import httpresponseredirect django.core.urlresolvers import reverse  # create views here. .forms import emailform, testform .models import test  def home(request):    # print request.post["email"], request.post["email2"]     form = emailform(request.post or none)    if form.is_valid():       first_name = form.cleaned_data['first_name']       last_name = form.cleaned_data['last_name']       email = form.cleaned_data['email']       new_test, created = test.objects.get_or_create(email = email,        first_name = first_name, last_name = last_name)      # # using model forms     # form = testform(request.post or none)     # if form.is_valid():     #     new_test = form.save(commit = false)     #     #we might here     #     email = form.cleaned_data['email']     #     new_test_old, created = test.objects.get_or_create(email = email)     #     # new_test.save()      context = {"form": form}     template = "home.html"     return render(request, template, context) 

this urls.py page

from django.conf.urls import patterns, include, url django.conf import settings django.conf.urls.static import static  django.contrib import admin admin.autodiscover()  urlpatterns = patterns('', # examples: url(r'^$', 'tests.views.home', name='home'), # url(r'^home2/$', 'lwc.views.home2', name='home'), # url(r'^blog/', include('blog.urls')),  #this admin can changed #link must changed access admin area url(r'^admin/', include(admin.site.urls)), ) 

the objective of app allow users upload file , submit associated sqlite database. how accomplish without media_root or media_url?


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -