python - Django Import by filename is not supported -




i new django , trying create file upload page following need minimal django file upload example instructions. however, keep getting "import file not supported" error.

actual error seems happening here:

c:\users\306432857\appdata\local\continuum\anaconda\lib\importlib\__init__.py in import_module             __import__(name) ... 

full traceback:

    environment:   request method: request url: http://127.0.0.1:8000/  django version: 1.8 python version: 2.7.13 installed applications: ('django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'myapp') installed middleware: ('django.contrib.sessions.middleware.sessionmiddleware',  'django.middleware.common.commonmiddleware',  'django.middleware.csrf.csrfviewmiddleware',  'django.contrib.auth.middleware.authenticationmiddleware',  'django.contrib.auth.middleware.sessionauthenticationmiddleware',  'django.contrib.messages.middleware.messagemiddleware',  'django.middleware.clickjacking.xframeoptionsmiddleware',  'django.middleware.security.securitymiddleware')   traceback: file "c:\users\..\appdata\local\continuum\anaconda\lib\site-packages\django-1.8-py2.7.egg\django\core\handlers\base.py" in get_response   119.                 resolver_match = resolver.resolve(request.path_info) file "c:\users\..\appdata\local\continuum\anaconda\lib\site-packages\django-1.8-py2.7.egg\django\core\urlresolvers.py" in resolve   368.                     sub_match = pattern.resolve(new_path) file "c:\users\..\appdata\local\continuum\anaconda\lib\site-packages\django-1.8-py2.7.egg\django\core\urlresolvers.py" in resolve   240.             return resolvermatch(self.callback, args, kwargs, self.name) file "c:\users\..\appdata\local\continuum\anaconda\lib\site-packages\django-1.8-py2.7.egg\django\core\urlresolvers.py" in callback   247.         self._callback = get_callable(self._callback_str) file "c:\users\..\appdata\local\continuum\anaconda\lib\site-packages\django-1.8-py2.7.egg\django\utils\lru_cache.py" in wrapper   101.                     result = user_function(*args, **kwds) file "c:\users\..\appdata\local\continuum\anaconda\lib\site-packages\django-1.8-py2.7.egg\django\core\urlresolvers.py" in get_callable   112.             if submod , not module_has_submodule(import_module(parentmod), submod): file "c:\users\..\appdata\local\continuum\anaconda\lib\importlib\__init__.py" in import_module   37.     __import__(name)  exception type: importerror @ / exception value: import filename not supported. 

urls.py

from django.conf.urls import patterns, include, url django.conf import settings django.conf.urls.static import static django.contrib import admin import myapp  #from django_project import myapp #from myapp import views myapp_views  urlpatterns = [     # examples:     # url(r'^$', 'django_project.views.home', name='home'),     # url(r'^blog/', include('blog.urls')),     url(r'^$', 'http://127.0.0.1:8000/home/', name='home'),     url(r'^admin/', include(admin.site.urls)),     url(r'^', include('myapp.urls')) ] + static(settings.media_url, document_root=settings.media_root) 

myapp/urls.py

from django.conf.urls import patterns, include, url #from django_project import myapp import views myapp_view   urlpatterns =  [     #url(r'^list/$', include('myapp.views'))     url(r'^list/$', myapp_view.list, name='list') ] 

views.py

from django.shortcuts import render  # create views here. django.shortcuts import render_to_response django.template import requestcontext django.http import httpresponseredirect django.core.urlresolvers import reverse  myapp.models import document myapp.forms import documentform  def list(request):     # handle file upload     if request.method == 'post':         form = documentform(request.post, request.files)         if form.is_valid():             newdoc = document(docfile = request.files['docfile'])             newdoc.save()              # redirect document list after post             return httpresponseredirect(reverse('myapp.views.list'))     else:         form = documentform() # empty, unbound form      # load documents list page     documents = document.objects.all()      # render list page documents , form     return render_to_response(         'myapp/list.html',         {'documents': documents, 'form': form},         context_instance=requestcontext(request)     ) 





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -