473,473 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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/xxxxx/

where xxxxx represents the domain name.

How can I find the domain name of the current url being viewed.
Sep 23 '08 #1
10 2453
Bobby Roberts 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/xxxxx/

where xxxxx represents the domain name.

How can I find the domain name of the current url being viewed.
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

Sep 23 '08 #2
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.

Sep 23 '08 #3
On Tue, Sep 23, 2008 at 8:37 AM, Bobby Roberts <tc*******@gmail.comwrote:
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/xxxxx/

where xxxxx 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.
Sep 23 '08 #4
On Sep 23, 8:54*am, "Joe Riopel" <goo...@gmail.comwrote:
On Tue, Sep 23, 2008 at 8:37 AM, Bobby Roberts <tchend...@gmail.comwrote:
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/xxxxx/
where xxxxx 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?
Sep 23 '08 #5
On Sep 23, 9:10*am, Tino Wildenhain <t...@wildenhain.dewrote:
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).
Sep 23 '08 #6
Bobby Roberts a écrit :
On Sep 23, 9:10 am, Tino Wildenhain <t...@wildenhain.dewrote:
>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).
Please don't compare apples to roller-skates. asp is a mix of libraries,
components and whatever, while Python is a language.
Sep 23 '08 #7
On Sep 23, 1:23*pm, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
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/xxxxx/
where xxxxx 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.
Sep 23 '08 #8
En Tue, 23 Sep 2008 09:37:44 -0300, Bobby Roberts <tc*******@gmail.com>
escribió:
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/xxxxx/

where xxxxx represents the domain name.

How can I find the domain name of the current url being viewed.
That info comes from the "Host" request field, and whether it's available
or not depends on the web framework in use; for a plain old CGI script, it
depends on the server configuration. Look at the HTTP_HOST environment
variable (accessing os.environ, or with the cgi.print_environ() function)

--
Gabriel Genellina

Sep 24 '08 #9
Bobby Roberts a écrit :
On Sep 23, 1:23 pm, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
>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/xxxxx/
where xxxxx 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
Ok. So the informations you're looking for should be accessible as
attributes of the request object that get passed to your request
handler. Attributes of interest here are mostly request.hostname,
request.uri, request.path_info and request.filename. More informations here:

http://www.modpython.org/live/curren...quest-mem.html

over an in-house framework written years ago
Mmm... Then you might want to checkout which version of mod_python
you're using, and make sure you read the corresponding doc...

FWIW, there's also a mod_python mailing-list, so I suggest you seek
further assistance wrt/ mod_python specific stuff there. Of course,
questions about the Python language and it's standard lib are welcome here.
without
documentation
use the code, young jedi !-)
so it's not the easiest thing to navigate. We will be
moving to django this fall.
Sep 24 '08 #10
In message
<09**********************************@y21g2000hsf. googlegroups.com>, Bobby
Roberts wrote:
evidently the environ dictionary is off limits on our server.
Why?
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).
Unless, of course, the relevant information was off limits on your server.
Sep 24 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bilal | last post by:
Hi, I have a web application that operates on several windows. Each window is named win_1, win_2, win_3,... . When I quit a session, I usually loop through all the windows and close one by one. So...
7
by: Ewart MacLucas | last post by:
Does anybody know how to find the workgroup name (or domainname) of the local PC. Is there a framework class for it? (preferably a solution not involving active directory calls) Thanks,...
4
by: Mike | last post by:
Greetings, I am writing an Intranet application in ASP.NET using VB.NET. I am obtaining the username of the user with: uName = User.Identity.Name, which is in the form of DOMAIN\username. I...
5
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the...
4
by: UJ | last post by:
I have a need to know what the domain name is when I'm running a site. Essentially the problem I have is that I let the user build a web page and then I display it using a IFRAME. But the IFRAME...
2
by: NathanC | last post by:
'*********************************************** Dim MySearcher As New DirectorySearcher("LDAP://CN=Users,DC=corporate,DC=domainname,DC=com") ' Create a DirectorySearcher object. Dim resEnt As...
2
by: jd | last post by:
hi all, i'm using regular expression to find the url of the page to be opened using the window.open(). typical urls look like this http://domain.com/path-to-page.html right now i'm trying...
0
by: =?Utf-8?B?TGFlZWxpbg==?= | last post by:
I'm trying to write a simple c# application that lets you enter a domain name in one box, and it returns the IP address and the nameservers of the domain. The problem is that while getting the IP...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.