finding domain name
hi group. I'm new to python and need some help and hope you can answer this question. I have a situation in my code where i need to create a file on the server and write to it. That's not a problem if i hard code the path. However, the domain name needs to be dynamic so it is picked up automatically. The path to our websites is home/sites/x/ where x represents the domain name. How can I find the domain name of the current url being viewed. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding domain name
> Depends on the technology/web framework. If you use WSGI, you should use > something like: > > host_name = environ.get("HTTP_HOST", None) or environ["SERVER_NAME"] > > -- Gerhard Yeah i already tried environ("SERVER_NAME") but get a key error when i do. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding domain name
On Sep 23, 8:54 am, "Joe Riopel" <[EMAIL PROTECTED]> wrote: > On Tue, Sep 23, 2008 at 8:37 AM, Bobby Roberts <[EMAIL PROTECTED]> wrote: > > hi group. I'm new to python and need some help and hope you can > > answer this question. I have a situation in my code where i need to > > create a file on the server and write to it. That's not a problem if > > i hard code the path. However, the domain name needs to be dynamic so > > it is picked up automatically. The path to our websites is > > > home/sites/x/ > > > where x represents the domain name. > > > How can I find the domain name of the current url being viewed. > > I would guess that a pretty simple regular expression might do it. can you explain? -- http://mail.python.org/mailman/listinfo/python-list
Re: finding domain name
On Sep 23, 9:10 am, Tino Wildenhain <[EMAIL PROTECTED]> wrote: > Bobby Roberts wrote: > >> Depends on the technology/web framework. If you use WSGI, you should use > >> something like: > > >> host_name = environ.get("HTTP_HOST", None) or environ["SERVER_NAME"] > > >> -- Gerhard > > > Yeah i already tried environ("SERVER_NAME") but get a key error when i > > do. > > You could output the whole environ to see what you get and how it is called. > > I'd recommend however to check that you are using a configured value and > not something sent by the client if you are going to use it during > filesystem lookup. > > Regards > Tino > > smime.p7s > 4KViewDownload evidently the environ dictionary is off limits on our server. It can't be that tough in python to get the current complete url being viewed. It's a snap in asp(which is my background). -- http://mail.python.org/mailman/listinfo/python-list
Re: finding domain name
On Sep 23, 1:23 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Bobby Roberts a écrit : > > > hi group. I'm new to python and need some help and hope you can > > answer this question. I have a situation in my code where i need to > > create a file on the server and write to it. That's not a problem if > > i hard code the path. However, the domain name needs to be dynamic so > > it is picked up automatically. The path to our websites is > > > home/sites/x/ > > > where x represents the domain name. > > > How can I find the domain name of the current url being viewed. > > What are you using exactly ? cgi ? wsgi ? Else ? mod python over an in-house framework written years ago without documentation so it's not the easiest thing to navigate. We will be moving to django this fall. -- http://mail.python.org/mailman/listinfo/python-list
empty csv file attachments
hi group. I'm new to python but a veteran at programming. This one has me stumped. I have a simple contact form which the user fills out. The email is sent to the site user as well and it is delivered with the content in the body of the email as well in nice order. I have modified my code to also send the content as a csv attachment. On the server, the file is perfectly generated with content. The attachment, however, is completely blank. Any ideas what that could be? My code snippet is shown below: if int(attachmenttype)==2 or int(attachmenttype)==3: for field in ctx.request.field_names(): if field=='last_name': myfilename=ctx.request.field_value(field)+'.txt' if myfilename=='': myfilename='tempfile.txt' mypath= mynewfilepath + '/' + myfilename f=open(mypath, 'w') mynewstring='' counter=0 for field in ctx.request.field_names(): if field != 'inquiry_required': mynewstring=mynewstring + field +',' if mynewstring[-1]==',': mynewstring=mynewstring[0:len(mynewstring)-1] f.write(mynewstring) f.write ('\n') mynewstring='' counter=1 for field in ctx.request.field_names(): fielddata=ctx.request.field_value(field) if counter==1: dummydata=0 else: mynewstring=mynewstring + '"' + fielddata.replace('"','') + '",' counter = counter + 1 if mynewstring[-1]==',': mynewstring=mynewstring[0:len(mynewstring)-1] f.write(mynewstring) f.write('\n') f.close attachments.append('/'.join((ctx.request.library, myfilename))) [snip... sends email just after this] any ideas? -- http://mail.python.org/mailman/listinfo/python-list
empty csv file attachments
hi group. I'm new to python but a veteran at programming. This one has me stumped. I have a simple contact form which the user fills out. The email is sent to the site user as well and it is delivered with the content in the body of the email as well in nice order. I have modified my code to also send the content as a csv attachment. On the server, the file is perfectly generated with content. The attachment, however, is completely blank. Any ideas what that could be? My code snippet is shown below: if int(attachmenttype)==2 or int(attachmenttype)==3: for field in ctx.request.field_names(): if field=='last_name': myfilename=ctx.request.field_value(field)+'.txt' if myfilename=='': myfilename='tempfile.txt' mypath= mynewfilepath + '/' + myfilename f=open(mypath, 'w') mynewstring='' counter=0 for field in ctx.request.field_names(): if field != 'inquiry_required': mynewstring=mynewstring + field +',' if mynewstring[-1]==',': mynewstring=mynewstring[0:len(mynewstring)-1] f.write(mynewstring) f.write ('\n') mynewstring='' counter=1 for field in ctx.request.field_names(): fielddata=ctx.request.field_value(field) if counter==1: dummydata=0 else: mynewstring=mynewstring + '"' + fielddata.replace('"','') + '",' counter = counter + 1 if mynewstring[-1]==',': mynewstring=mynewstring[0:len(mynewstring)-1] f.write(mynewstring) f.write('\n') f.close attachments.append('/'.join((ctx.request.library, myfilename))) [snip... sends email just after this] any ideas? -- http://mail.python.org/mailman/listinfo/python-list
csv files for download
I need to be able to offer a client "click to download" functionality on their website. Generating the data to provide to them is not an issue but I want them to be able to click a button and have the response be sent to a csv file which they are prompted to download. Can someone point me in the right direction how to do this in python. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list