Re: Development Server Ignores IP-address Parameter

2015-07-16 Thread Ted Thomas
Jonathan, anotherdjangonewby,

Thanks.  I tried both suggestions, but there in no change in behavior.  No 
matter what I do,
the development server only takes requests at 127.0.0.1:8000.

I am including my settings.py file below ( with altered secret_key):




"""
> Django settings for app3 project.
>
> For more information on this file, see
> https://docs.djangoproject.com/en/1.7/topics/settings/
>
> For the full list of settings and their values, see
> https://docs.djangoproject.com/en/1.7/ref/settings/
> """
>
> # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
> import os
> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
>
> #wfk debug
> print("WFK: BASE_DIR= " + BASE_DIR)
>
> # Quick-start development settings - unsuitable for production
> # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
>
> # SECURITY WARNING: keep the secret key used in production secret!
> SECRET_KEY = ''
>
> # SECURITY WARNING: don't run with debug turned on in production!
> DEBUG = True
>
> #TEMPLATE_DEBUG = True  #wfk.  This is deprecated with Django 1.8
>
> #ALLOWED_HOSTS = []
> ALLOWED_HOSTS = ['192.168.0.102']
>
> # Application definition
> INSTALLED_APPS = (
> 'django_pdb', #wfk for django-pdb debugger
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'report_builder',
> 'app3',   #wfk. Application #3
> 'bootstrap3',
> )
>
> MIDDLEWARE_CLASSES = (
> '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_pdb.middleware.PdbMiddleware', #wfk for django-pdb debugger
> )
>
> ROOT_URLCONF = 'app3.urls'  #WFK app3 is in BASEPATH
> #ROOT_URLCONF = 'urls'
> print("WFK: ROOT_URLCONF= " + ROOT_URLCONF) #DEBUG
>
> WSGI_APPLICATION = 'app3.wsgi.application'
>
> #Wfk: This stanza removed when upgrading to Django 1.8.  See "TEMPLATES =" 
> below.
> #TEMPLATE_CONTEXT_PROCESSORS = ( # wfk added this for img processing
> #"django.contrib.auth.context_processors.auth",
> #"django.core.context_processors.debug",
> #"django.core.context_processors.i18n",
> #"django.core.context_processors.media",
> #"django.core.context_processors.static",
> #"django.core.context_processors.tz",
> #"django.contrib.messages.context_processors.messages"
> #)
>
> TEMPLATES = [ # wfk added this when upgrading from Django 1.7.1 to 
> 1.8.2
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [
> # insert your TEMPLATE_DIRS here
> ],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
> # list if you haven't customized them:
> 'django.contrib.auth.context_processors.auth',
> 'django.template.context_processors.debug',
> 'django.template.context_processors.i18n',
> 'django.template.context_processors.media',
> 'django.template.context_processors.static',
> 'django.template.context_processors.tz',
> 'django.contrib.messages.context_processors.messages',
> ],
> 'debug':True,#wfk: Do TEMPLATE debugging.  Replaces 
> TEMPLATE_DEBUG. See 1.8 upgrade stuff
> },
> },
> ]
>
> # Database
> # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
>
> DATABASES = {
>
># For postgres:
> # USER, PASSWORD, HOST are needed
> # Inside postgres, "CREATE DATABASE database_name"
>
>  'default': {
>  'ENGINE': 'django.db.backends.postgresql_psycopg2',
>  #'NAME': 'app_1_db',  # Change to app3 later !!!
>  'NAME': 'app3_db',  
>  'USER': 'bill',
>  'PASSWORD': 'bill',
>  'HOST': '127.0.0.1',
>  'PORT': '5432',
> #'ATOMIC_REQUESTS': True,  # Safe! See "Two Scoops" p 72
>  }
>
> }
>
> # Internationalization
> # https://docs.djangoproject.com/en/1.7/topics/i18n/
>
> LANGUAGE_CODE = 'en-us'
>
> #TIME_ZONE = 'UTC'
> TIME_ZONE = 'America/Los_Angeles'
>
> USE_I18N = True
>
> USE_L10N = True
>
> USE_TZ = True
>
>
> # Static files (CSS, JavaScript, Images)
> # https://docs.djangoproject.com/en/1.7/howto/static-files/
>
> STATIC_URL = '/static/'  # refers to 
> /home/bill/web_server/django/proj3/app3/static
> STATIC_PATH = os.path.join(BASE_DIR,'app3/static/') #wfk 16-dec-2014
> #wfk debug
> print("WFK: STATIC_PATH= " + STATIC_PATH)
> STATICFILES_DIRS =

How to use Python Requests Module to upload images to Django Application?

2015-07-23 Thread Ted Thomas
I am developing a django application that primarily uses web browsers to 
upload scientific data that includes some image files.  Currently, the 
application works fine when Firefox or Chrome are used.  Both images and 
other data are correctly uploaded.

Occasionally users need to upload larger amounts of data, so I want to 
automate this using Python's Requests module.  My python program currently 
uploads non-image data, but Django is not receiving the image files.   This 
may be because I am not setting HTTP-headers correctly.

When the user agent is Firefox, requests received by Django include headers 
like:

  HTTP_ACCEPT_ENCODING   gzip, deflate
  HTTP_ACCEPT   
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

When the user agent is my standalone program, only:

  HTTP_ACCEPT_ENCODING   identity

My questions are:

  1) What HTTP-headers is Django expecting?

  2) Should I be gzipping the image files?

  3) What is the correct way to do this?

A code snippet from my standalone program follows.

==
# loop to get messages from console
while True:
   message = input("Enter msg string: ")
   filename= input("Enter filename (or blank): ")

   # GET
   print("--- GET upload_msg")
   # Create a GET request (but do don't sent it)
   req   = Request('GET', upload_msg_url, data= {})
   # Send request
   forms_dct= get_response(req)

   # modify forms_dct from GET, and use in next get_response()
   forms_dct['message_str'] = message

   # open file for upload
   fobj = open(filename,'rb')
   # modify forms_dct from GET, and use in next get_response()
   forms_dct['photo'] = filename

   # Create files dictionary
   files_dct = {filename:fobj}

   # POST
   print("--- POST upload_msg")
   # Create a POST request (but do don't sent it)
   req   = Request('POST', upload_msg_url, data= forms_dct, files= 
files_dct)
   # Send request
   forms_dct   = get_response(req) 

   # close file
   fobj.close()
==

Thanks.






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/79a3f85c-b85a-44d1-b7d6-bf150eb35978%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to use Python Requests Module to upload images to Django Application?

2015-07-23 Thread Ted Thomas

My Python code started working after I changed on line.

Changing:
 files_dct = {filename:fobj}
to:
files_dct = {('photo',(filename, fobj,'image/jpg'))}

Now it works.  My conjecture about the need for different HTTP-headers was 
wrong.  The working code has not changed the headers received by Django.

I must say, the Requests module documentation is very opaque!

I made this change based on a guess while reading the docs about sending 
multiple files.  I can't say I understand what going on.

Please comment on the right way to do this.  



>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab20873c-7e7e-4817-82f8-1a691a2cfa14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.