404 Not Found

45 wyświetleń
Przejdź do pierwszej nieodczytanej wiadomości

braydon fuller

nieprzeczytany,
3 lut 2008, 18:29:523.02.2008
do cherrypy-users
Hi,

I am using my own 404 error page that allows
users to create URIs. However, because of this, every URI will be
returned as 202 successful, as i'm not using CP error class. How can I
tell
cherrypy to delivery the page w/ the 404 not header response?

For example, below is the code I'm using for each request:

def render(args, kwargs, location_st=None):
settings = Settings()
if len(args) >= 1:
location = []
for arg in args:
location.append(arg)
location_id = "-".join(location)
try:
get_uri(location_id)
return render_skeleton(location_id, location_st, kwargs)
except IndexError:
site_name = settings.root.site_name
session = get_session()
user = session["user"]
group = session["group"]
notfound =
Template(file=settings.root.core_views_path+"/404.tmpl",
searchList=[locals()])
body = notfound.respond()
cmds_array = ""
head = render_head(location, location_st, cmds_array)
t =
Template(file=settings.root.core_views_path+"/skeleton.tmpl",
searchList=[locals()])
return t.respond()
else:
location ="r"
location_st = settings.root.site_name
return render_skeleton(location, location_st, kwargs)

this is called by:

class Root():
def __init__(self):
self.cmd = __import__('exposed', globals(), locals(),
['sparrow'])
db.create_all()

def default(self, *args, **kwargs):
location_st = ""
for arg in args:
location_st += "/"+arg
try:
return render(args, kwargs, location_st)
except:
db.start_engine()
return render(args, kwargs, location_st)
default.exposed = True

which is started by:

if __name__ == "__main__":
cherrypy.quickstart(Root(), '/', config="config/.conf")


-Braydon

braydon fuller

nieprzeczytany,
3 lut 2008, 21:20:053.02.2008
do cherrypy-users
I've solved this with a patch to cherrypy._cperror.py :)

There is a post about it on cherrpy-devel here:
http://groups.google.com/group/cherrypy-devel/browse_frm/thread/7ab58f345d8e650c

The _cperror.py can be located here:
http://groups.google.com/group/cherrypy-devel/web/_cperror.py

The patch allows you to be able to do something like the following:

def foobar(uri):
try:
location = get_uri(uri)
data = get_data(location)
success = Template(file=filename, searchList=[data])
return success.respond()
except:
error = Template(file=filename, searchList=[locals()])
raise HTTPError(404, body=error)
foobar.exposed = True

-Braydon

braydon fuller

nieprzeczytany,
3 lut 2008, 17:29:343.02.2008
do cherryp...@googlegroups.com
Hi,

I am overriding cherrypy's 404 error page with my own 404 not found page
based on a db query for that URI. This 404 not found page allows the
user to create the URI. However, because of this, every URI will be
returned as 202 successful. How can I tell cherrypy to delivery the page


w/ the 404 not header response?

I've tried to create an Exception Class based on CP's NotFound, but w/
no success.

this is called by:

which is started by:


-Braydon

--
bgfuller braydon.com
626.298.6570 land
323.841.0048 air
117.121.243.13 web
LA CA USA

Odpowiedz wszystkim
Odpowiedz autorowi
Przekaż
Nowe wiadomości: 0