Where to store email templates? - django

I'm writing a Django 1.4 app that will send HTML email. I'm using Django templates to render the email content, but I'm unsure how to store the templates.
I can store them in an email app (like I would other templates), but it feels silly to use a static file.
I thought about creating an Email model and storing the template code as a TextField, which would work.
I searched for better solutions and saw sendwithus.com on reddit, which is a neat idea...
Is there a Django convention for this sort of thing?

The general approach is to store email templates either globally in the project template folder or in the template folder of your email app. If you build a reusable app you can provide examples of email templates in your apps template folder, but make it possible to overwrite them via global project template (prioritize project templates before app templates in TEMPLATE_READERS, usually the default in django).
I think you other ideas are overkill for something so simple.

Related

Django - Best way to organize/serve mostly static website?

My friend with very little coding experience began making a business site and passed it on to me. Currently, it is mostly static html and css files but I want to take what he has and build on it using Django because I will be adding features like user login/auth and checkout. I was wondering what the best thing to do with all these html and css files are and how I might go about fitting it to Django framework.
All of the content on these pages will be static but I could imagine in the future once I add a login, the header might be different to show whether or not a user is logged in. Would I need to make separate apps for each page, include them all in one app, or just put them all in the static folder?
Would I need to make separate apps for each page
Assuming you are referring to django apps. Then No, you do not need to create a separate application for each page. django apps are a way to organize individual pieces of your projects.
To gain the most out of django, I would suggest looking into the Django Template Engine to improve the html (blocks, include and extend etc) and make it more readable and future proof ( urls, media, forms)
just put them all in the static folder?
I'm not sure you'd be able to get away with it being in the static folder, Static files in django are used for CSS and Media files such as images, videos etc. To render a template in django you need use render() or TemplateView
I hope this helps clear up some of your doubts.
Django is a Model-View-Template (MVT) framework where you create templates (HTML files) and use Jinja syntax there to display the data passed from Django views. You don't need to create apps for each page, instead, you can define functions in an app's views.py file and then reference that view from the corresponding path (URL) from the urls.py file.
You can create a main HTML template that will be extended by each sub-page. And applying your logic to your main template's header (i.e. if/else) in the main template will affect your all pages.
My recommendation is that you should first study the Django docs carefully and understand at least it's basics before starting the migration of the HTML site to Django. Django has one of the best documentation available for software on the Internet and you should be grasping the basics very quickly if you have a little programming background.

how to style Server templates in meteor

I have a file in my /private folder which I then use for SSR.compileTemplate and SSR.render to send nice html verification email; is it possible to style it with bootstrap as well? if so where I should put the real client-like template file ?
If its for email template you will need inline styles in order to make it work with most of the email services, so you just use a css inliner(like this one http://foundation.zurb.com/emails/inliner.html).
Another problem you might find is that some features don't work, like media queries, so its possible that your bootstrap styles don't look as you wanted.
I recommend you to use the zurb foundation emails, It has great compatibility with most of the email clients http://foundation.zurb.com/emails.html

Django equivalent to Rails application_controller

In Rails, I used the application_controller to control things like user sessions, and create objects to populate parts of the site like the menu.
How should this be done in Django, since there is no kind of "application view"? Do you have to use custom filters and partial templates to be included, for instance in the base template to do this?
I have also been looking at class-based views, but am unsure if that is it.
There are several ways to accomplish this:
Template Tags
Context Processors
Class Based Views
Middleware
It just depends on what you're needing to do. request.user is always present in the request object, even if it's an anonymous user, so you don't have to do anything special to access that object from within a template or server-side code.
Inclusion tags are as close as you'll get to render partial in Rails.
Signals and Class-Based views are close to what you'd find in controller filters.
One of the books I found most helpful when learning Django (I went to Django from Rails) was Practical Django Projects. The Definitive Guide to Django is also available for free.

How would you allow users to extend off a Django site for templating purposes?

I'm building a Django site, and like a blog, I'd like users to further extend the content off the site by "skinning" through templates.
I'd like to re-use Django templating for this, I've been brainstorming on this but haven't gotten a solid idea how I can do this, can I hear some of your brilliant suggestions?
Thanks!
Probably the cleanest way is to write really semantic HTML, allow various bits of it to be configured using dbsettings (e.g. site names etc), then allow the user to add their own CSS file (perhaps by allowing the path to a CSS file to be managed through dbsettings).

Using django models across apps?

So in my Django project I have a few different apps, each with their own Models, Views, Templates, etc. What is a good way (the "Django" way) to have these Apps communicate?
A specific example would be a Meetings App which has a model for Meetings, and I have a Home App in which I want to display top 5 Meetings on the home page.
Should the Home App's View just query the Meetings App's Model?
It feels like that is crossing some line and there might be a more de-coupled way to do things like this in Django.
At some point your apps will have to couple in order to get any work done. You can't get around that.
To achieve decoupling as much as possible,
You need to have a Project specific app, that does all the hooking up things between each other.
Using signals from models to create new models in a decoupled apps helps. But doing too much of this, is foolish.
Should the Home App's View just query the Meetings App's Model?
Yep, that's how it's done. If you really want to decouple things, you could make your Home app use generic foreign keys, and some sort of generic template system, but there's not really a good reason to, unless you have grand plans for your home app being pluggable and working with a bunch of other different Django apps.
Writing tightly coupled Django apps is really easy, and writing decoupled Django apps is really hard. Don't decouple unless you have a reason to, and you'll save yourself a lot of work (and happiness!).
If it were me, I would make a template tag in your meeting app that produces the desired output and include that template tag in the home app's template.
That way you are only coupling them in the View portion of the MVC and makes it easier to maintain if you change your models in the meeting app.
For your specific example, I would use a Django templatetag.
Having a templatetag "display_top_meetings" in your Meetings app, and calling it with {{ display_top_meetings 5 }} from your index template, loading it first.
You can read more about templatetags here:
Django Official documentation about TemplateTags
B-List's article on writting 'better template tags'
I hope this help!
yes. I think thats a design feature. All models share a backend, so you'd have to do extra work to have two models with the same name in different apps.
Projects should not share Models