寻找域名 [英] finding domain name

查看:52
本文介绍了寻找域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我是python的新手,需要一些帮助,希望你能回答这个问题。
回答这个问题。我的代码中有一种情况我需要在服务器上创建一个文件并写入它。如果

我硬编码路径,这不是问题。但是,域名需要是动态的,所以

会自动获取。我们网站的路径是


home / sites / xxxxx /


其中xxxxx代表域名。

如何找到当前正在查看的网址的域名。

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.

推荐答案

Bobby Roberts写道:
Bobby Roberts wrote:

hi group。我是python的新手,需要一些帮助,希望你能回答这个问题。
回答这个问题。我的代码中有一种情况我需要在服务器上创建一个文件并写入它。如果

我硬编码路径,这不是问题。但是,域名需要是动态的,所以

会自动获取。我们网站的路径是


home / sites / xxxxx /


其中xxxxx代表域名。

如何查找当前正在查看的网址的域名。
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.



取决于技术/网络框架。如果您使用WSGI,您应该使用

类似于:

host_name = environ.get(" HTTP_HOST",None)或environ [" SERVER_NAME" ;]


- Gerhard

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



取决于技术/网络框架。如果您使用WSGI,您应该使用

类似于:

host_name = environ.get(" HTTP_HOST",None)或environ [" SERVER_NAME" ;]


- Gerhard
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



是的,我已经尝试了environ(SERVER_NAME),但在获取时出现了一个关键错误我是b $ b。

Yeah i already tried environ("SERVER_NAME") but get a key error when i
do.


2008年9月23日星期二上午8:37,Bobby Roberts< tc ** *****@gmail.com写道:
On Tue, Sep 23, 2008 at 8:37 AM, Bobby Roberts <tc*******@gmail.comwrote:

hi group。我是python的新手,需要一些帮助,希望你能回答这个问题。
回答这个问题。我的代码中有一种情况我需要在服务器上创建一个文件并写入它。如果

我硬编码路径,这不是问题。但是,域名需要是动态的,所以

会自动获取。我们网站的路径是


home / sites / xxxxx /


其中xxxxx代表域名。

如何查找当前正在查看的网址的域名。
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.


这篇关于寻找域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆