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!

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. Anonymous8:32 AM

    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
  3. 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
  4. 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
  5. Anonymous10:40 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
  6. Anonymous1:49 AM

    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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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

Post a Comment

Popular posts from this blog

Coke Studio: Madari English Meaning and Lyrics

AJAX और हिंदी

Sadi Gali - Punjabi Lyrics and Meaning (in English) - Tanu Weds Manu

Tune Meri Jaana Kabhi Nahin Jaana - Lonely (Emptiness) - IIT Guwahati - Rohan Rathore

Solved? LaTeX Error: pdf file is damaged - attempting to reconstruct xref table