Thursday, August 27, 2009

Automatic Django Template Directory adjustment

Django is that hot new MVC framework on the block that's kept me sleeping at night, quite unlike PHP. Yup, its that good! :) It's got wonderful features that make me feel - Yeah! Development for the web is still worth the grind! By the way, if you're not into Web Development and don't care two hoots about the difference between a framework and a library, this post is not for you - Mosey along now! Nothing to see here. ;)

Anyway, one of my few n00b questions to which I've never actually got a satisfactory answer is - How do you specify the template directory so that you can send your code to others and have it execute by manage.py runserver without any changes? The primary problem is the hardcoding of directories that is done in the settings.py file at the root of the project. After a bit of searching, I've come to a satisfactory solution and lest I forget it, I've decided to post it to my blog. Here's the code snippet.


TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# os.path.realpath(os.path.curdir).replace("\\", "/") + "/templates",
os.path.abspath(os.path.dirname(__file__)).replace("\\", "/") + "/templates"
)

This seems to work most of the time, just let me know how it works out for you!

19 comments:

  1. i experimented with django. i loved it. except for the fact that i prolly did it at the wrong time. the API changes in subsequent were sooo much that my old code just refuses to work, which makes me feel terrible. :) good luck!

    ReplyDelete
  2. http://www.keralaflowersgifts.com
    Send gifts to Kerala, Online delivery of flowers to Kerala, gift to Kerala chocolates, cakes, watches, teddy, sweets, fresh fruits, dry fruits.
    Anniversary, birthday, wedding gifts, cakes to Kerala Mithai Same day delivery to Kerala Gift Shop.

    ReplyDelete
  3. http://www.flowerdeliveryindia.com
    Send gifts to India, Online delivery of flowers to India, gift to India, chocolates, cakes, watches, teddy, sweets, fresh fruits, dry fruits.
    Anniversary, birthday, wedding gifts Same day delivery to India & all countries.

    ReplyDelete
  4. Send flowers, roses, cakes, balloons, sweets, chocolates, dry fruits, gift baskets and gourmet hamper gifts for delivery in India through “www.rightflorist.in”, India's top online florist.

    Please visit:
    www.rightflorist.in

    ReplyDelete
  5. Anonymous10:02 PM

    Cool blog as for me. It would be great to read more concerning this theme.
    BTW check the design I've made myself Russian escort

    ReplyDelete
  6. Send breathtaking gifts to USA and make a beguiling focal point to any celebration. Add unique beauty and style to the occasions of your special ones in USA with our exotic range of gifts.

    Please visit:
    www.expressgiftbasketsusa.com

    ReplyDelete
  7. www.fioriitaly.com
    We send flowers and gifts to all locations in Italy. We have relationship with flower growers and all flowers are sourced fresh direct from flower farms. Not only we ensure that the gifts you send are delivered on time, but also that they are as fresh as possible and deliver a great value to both the receiver and the person who sends flowers. The flowers designs we deliver are fresh and exclusive. If you are thinking of sending gifts to Italy, you need not go elsewhere. We send flowers and gifts to all locations in Italy. We have relationship with flower growers and all flowers are sourced fresh direct from flower farms. Not only we ensure that the gifts you send are delivered on time, but also that they are as fresh as possible and deliver a great value to both the receiver and the person who sends.

    ReplyDelete
  8. Anonymous12:10 PM

    We are an online florist always at your service. Service with top quality, lesser costs, high reliability and heart. Don't believe us. Simply experience it or even compare us. We know you will be with us and how we do it is simple! Some qualified directors, dedicated staff, top class & professional worldwide florist network of 1000's of florists penetrating countries states, cities & even small towns and of course a sound, smooth, fair & easy to use website based on high technology platform

    Please Visit:
    www.canadafloristonline.com

    ReplyDelete
  9. Send breathtaking flowers and gifts to India and make a beguiling focal point to any celebration. Add unique beauty and style to the occasions of your special ones in India with our exotic range of flowers and gifts.

    Please visit:
    www.gifts-to-india.com

    ReplyDelete
  10. Anonymous3:19 PM

    Send your good taste to celebration by delivering our mouthwatering cakes to Hyderabad and exotic flowers to Hyderabad and leave a cherished memory with them. Add zing to the special occasions of your acquaintances in Hyderabad by sending our fantastic flowers and tasty cakes.

    Please visit:
    www.hyderabadonlineflorists.com

    ReplyDelete
  11. Throw a zest to the special events of your associates in India by sending our spectacular flowers and exciting gifts. Our dedicated team offers robust customer service support for delivery of our flowers and gifts to India.

    Please visit:
    www.flowerdeliveryindia.com

    ReplyDelete
  12. We are leading online florist in Kolkata with the largest in Tamil Nadu. You may send flowers, cakes, chocolates, sweets & more gifts to Kolkata at over 12 locations across Tamil Nadu. Flowers, cakes & sweets to Kolkata can be sent with express delivery facility at over 8 locations in Tamil Nadu. We also deliver birthday gifts, anniversary gifts, and wedding gifts to Kolkata & all over Tamil Nadu on your desired date of delivery. Sending flowers & gifts to Kolkata & to other parts of Tamil Nadu was never so simple. Moreover, we guarantee delivery of orders. Enjoy the difference! Send flowers & gifts to Kolkata & all over Tamil Nadu today.

    Add zing to the special occasions of your acquaintances in Kolkata by sending our fantastic flowers and tasty cakes. Our expert team affords excellent customer service support for the delivery of our flowers and cakes to Kolkata. Our supreme delivery networks all over Kolkata, Same day delivery option to Kolkata and punctual delivery of flowers and cakes to Kolkata have helped us to be more proficient. Moreover sending flowers and cakes to Kolkata online with us is 100% secured.

    Please visit:
    www.kolkataonlineflorists.com

    ReplyDelete
  13. Add a zesty surprise to the celebrations of your loved ones. Convey your heartfelt appreciation for your dear ones in United States of America with our stunning flower arrangements, fresh fruits, sensational gift hampers, lip-smacking gourmet hampers, yummy chocolates, stirring holiday hampers, delicious cakes and more gifting options. Just place an order online with us for delivery of flowers and gifts anywhere in USA.

    Please visit:
    www.giftflowersusa.com

    ReplyDelete
  14. Send your good taste to celebration by delivering our mouthwatering cakes to Delhi and exotic flowers to Delhi and leave a cherished memory with them. Add zing to the special occasions of your acquaintances in Delhi by sending our fantastic flowers and tasty cakes.

    Please visit:
    www.delhiflowersgifts.com

    ReplyDelete
  15. Send your good taste to celebration by delivering our mouthwatering cakes to Chennai and exotic flowers to Chennai and leave a cherished memory with them. Add zing to the special occasions of your acquaintances in Chennai by sending our fantastic flowers and tasty cakes.

    Please visit:
    www.chennaionlineflorists.com

    ReplyDelete
  16. Send your good taste to celebration by delivering our mouthwatering cakes to Kerala and exotic flowers to Kerala and leave a cherished memory with them. Add zing to the special occasions of your acquaintances in Kerala by sending our fantastic flowers and tasty cakes.

    Please visit:
    www.keralaflowersgifts.com

    ReplyDelete
  17. Send your good taste to celebration by delivering our mouthwatering cakes to Bhubaneswar and exotic flowers to Bhubaneswar and leave a cherished memory with them. Add zing to the special occasions of your acquaintances in Bhubaneswar by sending our fantastic flowers and tasty cakes.

    Please visit:
    www.bhubaneswarflowershop.com

    ReplyDelete
  18. I actually enjoyed reading through this posting.Many thanks.

    Send Flowers to Chennai

    ReplyDelete