I am working with python pyramid and basically I have defined a route like this:
config.add_route('metaschemaxml', '/metaschema/{id}/xml')
The view mapping metashemaxml is like this:
@view_config(route_name='metaschemaxml', renderer='string')
def metaxml_view(request):
schema = request.matchdict['id']
urlparams = request.query_string
urlparams.strip()
required = 0
for x in urlparams.split(','):
if "required=1" in x:
required = 1
rxml = '<?xml version="1.0" encoding="utf-8"?><eroot></eroot>'
try:
tags = DBSession.query(mtemplatexelem_model).filter(mtemplatexelem_model.template_id == int(schema)).order_by(mtemplatexelem_model.xelem_id).all()
rxml = getXMLFromQuery(tags, required)
except DBAPIError:
return Response("Error in DB", content_type='text/plain', status_int=500)
return Response(rxml, content_type='text/xml', charset='utf8')
All works well if for example I call:
http://localhost:6543/metaschema/1/xml
But if I do the same request by Ajax I get:
XMLHttpRequest cannot load http://172.26.16.28:6543/metaschema/1/xml. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
What do I need to do to allow the ajax request in pyramid?
Thanks, Carlos