In there I just want to express my thoughts about urls.py framework, I
want to propose myself solution.

What's the question?
==================

A project may be separated into many pieces of apps, and these apps
can be move to other places or reused, so the url of the apps maybe
changed, and how to easy deal with such change? And we also need to
assume that only apps which have url prefix need to think about. So a
app and some function of it can be see as:

http://domain/app_prefix/function/parameter

So we want to think about if the app_pefix can be easily changed or remapped.

And there are maybe three places we need to think about:

1. urls.py
2. views
3. template

How to solved it?
==============

It's just my opinion, welcome to disscuss.

1. Define app's prefix in someplaces
------------------------------------------------------------

There are many places:

a) in INSTALLED_APPS

INSTALLED_APPS = (
    ('apps.profile', 'profile'),
    ('apps.woodlog', 'blog'),
    ('apps.rss', 'rss'),
}

But in this way, how to easy get the apps name?

b) define a new dict in settings.py or other place:

APPS_PREFIX = (
    ('profile', 'profile'),
    ('blog', 'blog'),
    ('rss', 'rss'),
)

2. Remap rule
---------------------------

We can define a special string format in urls, for example, there are
many candidates:

a) '$blog/username/2006/04/04/2.html'
b) '%(blog)s/username/2006/04/04/2.html'
c) something else

So if we define a '$blog' or '%(blog)s' in urls.py or
HttpResponseRedirect or some places relative to URL, the remap rule
will be enabled.

First the remap machanism will find if there is a $ string or %()
string, if there is, it'll auto check the APPS_PREFIX, and find if
there is a match string, if it does so, replace the $ string or %()
string, and if it does not, replace $string or %(string)s be string.
So if the develop didn't define APPS_PREFIX that's ok.

In template, we can provide a default tag to do this definition:

<a href="{% urlmap '$blog' %}/username/2006/04/04/2.html'>{{ object.title }}</a>

I don't know if the appoach is simple enough, and if we do like this,
some things need to changed, for example the process of urlpattern,
HttpResponseRedirect, and default tag, maybe something I don't
remember.

--
I like python!
My Blog: http://www.donews.net/limodou
My Django Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to