osx - Importing a distributed python package from Django view -
i working on django project need search results amazon product advertising api. i've used api in php working on first django app. have signed , have amazon credentials, keys, secret keys, etc.
as shortcut, found , installed distributed python package here: https://bitbucket.org/basti/python-amazon-product-api/overview
question 1: , how access non-django-specific python package within django? need add reference package in settings? package example docs include import statement, seems work in django shell (at least no error msg):
>>>from amazonproduct import api >>>
question 2: when want send installed python package search query django view , template, how/where import package's objects?
i have python package installed in same local instance of python django (running python 2.7 , django 1.5 on mac os x 10.8.2).
i new both django , python. i've been able django models, views , templates working, , have of front-end scripting written parse , display xml results amazon product advertising api. , python package seems have need. need figure out how take advantage of package's ability create signed request, call amazon's restful service , parse resulting xml.
it seems you're little confused python's packages , django apps. know, django web framework written in python, thus, python package/module/file imported inside django's code.
django apps python packages, that's why can stuff from my_app import models
import models of my_app
. difference that, generally, django app comes in django specific files (models.py, views.py, urls.py
, etc ), hence need add them installed_apps
in settings.py
in order django stuff app need done (generating tables in it's models.py
example).
regarding question, amazonproduct
package it's indeed python package not django app -it doesn't have views.py
nor models.py
. it's python package provides friendly interface query amazon's data. means doesn't have append installed_apps
. want import wherever need in code. think inside views.py
handle logic of application.
resuming: wherever need access methods or classes or functions amazonproduct
package import (as described in answer) , instantiate objects or call methods need normally. passing data collect in file you're working at.
hope gives light. if have other doubt python's packages , modules please refer doc session very documented.
Comments
Post a Comment