On 29 sep, 12:25, serial coder <
serialcode...@gmail.com> wrote:
> Hi,
> i just discover your framework and i have some question about.
>
> The installation was fine and i have made my website application. Then i
> need some help :
>
> 1. how to make my application listening on
>
http://mydomain and not http://mydomain:port/myapp/? My port number in usage
> is 80. Maybe need to customize the setting but how and where ? can you provide
> an example ?
To bind your application on a different port than the default 8080
one, you have
two possibilities:
- Launch your application with the '-p' or '--port' option:
nagare-admin serve -p 80 myapp
- Create a configuration file to publish your application:
[publisher]
port = 80
then launch your application with:
nagare-admin serve -c <this_configuration_file> myapp
The available publishing options are described at
http://www.nagare.org/trac/wiki/PublisherConfiguration
(remember on Unix you need to be root to bind to a port < 1024)
To register your application as
http://mydomain/ and not only
http://mydomain/myapp, you need to put this little piece of Python
code at the
end of your `app.py` file (here I suppose you generated the
application skeleton
with the `create-app` command):
from nagare import component, wsgi
class WSGIApp(wsgi.WSGIApp):
def set_config(self, config_filename, conf, error, static_path,
static_url, publisher):
if publisher:
publisher.register_application(conf['application']
['path'], '', self, self)
app = WSGIApp(lambda: component.Component(Myapp()))
> 2. I would like to customize my error (40x, 50x, ... other than 200). how to
> do it thanks to Nagare ? Can you also provide some source code for that
> point ?
As Nagare is WSGI compliant, the easier way is to plug a WSGI
middleware in front
of your application. Several exist. For instance, in our own
applications, we use
this kind of middleware:
from webob import exc, Response
class ErrorMiddleware(object):
def __init__(self, app):
self.app = app
def check_http_status(self, http_status):
#-- Put here the code to handle the HTTP error status
if http_status == 404:
raise exc.HTTPMovedPermanently(location='http://
www.google.com')
#--
def handle_error(self, e):
if isinstance(e, Response):
return e
#-- Put here the code to handle Python exceptions
import traceback
traceback.print_exc()
return exc.HTTPMovedPermanently(location='http://
www.google.com')
#--
def start_response(self, start_response, status, *args):
self.check_http_status(int(status[:3]))
start_response(status, *args)
def __call__(self, env, start_response):
try:
return
self.app(env, lambda status, *args:
self.start_response(start_response, status, *args))
except Exception, e:
self.handle_error(e)(env, start_response)
return []
To create the wsgi pipe:
- add this code at the end of your `app.py` file:
def create_wsgi_pipe(app, options, config_filename, config,
error):
return ErrorMiddleware(app)
- add this line in the `[application]` section of the `conf/
myapp.cfg` file:
wsgi_pipe = myapp.app:create_wsgi_pipe
> 3. is there a way to make a buildin search engine to my web site ?
In our projects, we use several solutions, from simple 'like' SQL
queries on
specific database text fields to Whoosh (
http://pypi.python.org/pypi/
Whoosh)
or Lucence (
http://lucene.apache.org/solr/)
> 4. is possible to make an automatic mapping of the site ?
It's possible but you need to code your own, see next question.
> 5. if i have well understood how nagare is working, there is no links at all
> right ?
By default Nagare don't force you to explicitly map URLs to your
actions. Nagare
manages "links" to you.
> so what i can do if i need some ?
No problem. The creation of significative URLs is described at
http://www.nagare.org/trac/wiki/RestfulUrl
> 6. I have see that nagare manages it own querrystring but can i add my own
> parameters ?
As for the URL mapping, it's easier to let Nagare manage the URL
parameters. But
if you really need to handle your own parameters, the 'init_for()'
methods,
detailled in
http://www.nagare.org/trac/wiki/RestfulUrl, receive the
`request`
object and so you can access the URL parameters as `request.params`.
> 7. i immagine there is lot of component. is there a component repository
> where programmer can share their work to others ?
No, not yet.
> I know this is lot of questions but i need to understand more your framework
> before to continue.
Take your time to explore Nagare. It's different than a lots of
existing
frameworks. I hope you will enjoy it.
Regards