2

I have a problem where i have to send two urls of partially same format to different views.

eg. "domain/land/one-brush" will go to views.land(request, id) where id is "one-brush"

and similarly domain/land/one-brush/include/images/dot.jpg will be served statically either by custom view or django static serve.. i prefer static serve.

one thing i have in mind that to write two url patterns one for land// and other for land//anything/will/do. First will redirect to custom url and second one will be served statically..

Any better way would be appreciated.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Manoj hans
  • 1,705
  • 3
  • 11
  • 8
  • I think it's better to have two url patterns defined than to introduce logic in your url conf. – elssar Dec 22 '13 at 04:55

1 Answers1

0

see how django handles static files using django staticfiles app, note that static files should be put in a totally different directory then other files in your project

STATICFILES_DIRS = (
    "/home/special.polls.com/polls/static",
    "/home/polls.com/polls/static",
    "/opt/webfiles/common",
)

in a real world deployment django should not be serving static files, this work is better done by apache / nginx etc. or even better by some cdn like amazon's / rackspace / google storage etc.

separating static files is usually achieved by using some tool like django pipline that will also help you uglify your files, zip them etc.

anyway, if you still want to serve some urls that start with the same path, bare in mind that django will try to find the first match in the list, meaning you'll want to put:

domain/land/one-brush/include/images/

before:

domain/land/one-brush/
Guy Gavriely
  • 11,228
  • 6
  • 27
  • 42