I am learning Django and got it to work with wsgi. I'm following the tutorial here:
http://docs.djangoproject.com/en/1.1/intro/tutorial01/
My question is: how can I customize the look and feel of Django? Is there a repository of templates that "look good", kind of like there are for Wordpress, that I can start from? I find the tutorial counterintuitive in that it goes immediately toward customizing the admin page of Django, rather than the main pages visible to users of the site. Is there an example of a "typical" Django site, with a decent template, that I can look at and built on/modify? The polls application is again not very representative since it's so specialized.
any references on this would be greatly appreciated. thanks.
Search for generic CSS/HTML templates, and add in the Django template language where you need it. Because unless you are trying to skin a particular app (such as the admin system), there is nothing Django-specific about any of your HTML.
The fact that you're thinking in terms of Wordpress templates, and that you think the tutorial's poll application is highly specialised, are hints that you haven't really grasped what Django is. It isn't a content management system or a blog engine, although it can be used to build those things.
There's no such thing as a typical Django site, and it simply doesn't make sense to have pre-packaged templates, because the front end could be absolutely anything at all - like a poll.
You write the template like you would write any standalone HTML+CSS page, perhaps with placeholders for the content, then turn those placeholders into actual Django template tags. If you know how to do write HTML, then you know how to make a Django template.
Actually Django does not have a "look and feel". You are probably referring to the built in Django Admin application. That app comes with its own templates.
There are third party applications that can change the Admin interface, Django Grapelli is a great example.
For any other application you want to build yourself, or download. Most likely you'll have to do the templates yourself. In order to come up with something pretty you need to learn about CSS/HTML/JS and design principles as the Django Templates will quite likely be out of your way.
I always recommend HTML Dog for learning the basics of HTML, CSS and JS.
Related
This is not a HOWTO question, as it, as such, has been answered before here
I am trying to integrate Django with modern frontend framework, and I found that it is possible to store and render Django templates from models. Since it is not a standard, I am wondering what are the advantages (or disadvantages if that's the case) of file based templates.
Reading though the documentation, I have seen that it is recommended to actually cache templates and models as much as possible for best performance, so why would it not be recommended to store templates in the database? It seems very convenient to me that in doing so pages can be edited from the admin panel (where you can add a code editor), which, along with the rest framework and a front end framework synergize very well.
From my research, the template tags and template language seem to work and the context can be passed in a view as well. the only thing I cannot figure out is the {include .. } tag, as it does not seem to point to a view. (although a custom tag cam be made to have this function)
Can such a setup be used in production? or are there security/performance/other concerns?
It's not recommended because templates are the developer's responsibility, not the site admin's.
Otherwise, there's not much performance difference between reading files directly from filesystem and from database.
One drawback of this approach is you don't get revision history (using git, mercurial etc). Sure, you can implement something similar to save the revisions in the database, but then why not use the better tools which already exist?
There's a Django flatpages app which lets you save HTML content in database. But the purpose of the app is to allow site admins to edit HTML content, such as information for an "About Us" page, because writing this info is not a developer's responsibility.
I’m creating a big project with Django and wondering if it is sensible to use the HTML template structure for my front end or should I implement something like React? What are each of its benefits? Is it perfectly reasonable to use HTML templates for a big project? Any advice?
Django templates are quite fully featured, and performant, and I'd use them if I could meet the requirements in my project with them alone. Adding react will increase the tooling you'll need and have to maintain, so my team only introduced it after we started to need user interfaces that were react-like (it started when we implemented an in-app to do list). So your project requirements will really dictate if you want to invest additional development and devops energy into react in order to have a more instant-update/native-app-like feel, or not.
If you are unsure, I'd recommend starting with templates and introducing react later. It's entirely possible to run an app that uses templates for 90% of your app and react only where it's needed (we do this).
The thing with React is you need to have a good API in between your back-end and your front-end. I would recommend Django Rest Framework for that. Anyway, templates are nice to quickly get something up and running, something that is mostly display centered and you don't have to do too much scripting. React makes it easier to have a heavier front-end. However, templates can handle a lot of front end as well, just you won't get access to any of the nice benefits of React. I have used templates for a big project, and it worked nicely. I didn't have to build an API, and the templates easily interacted with my back-end. I am not sure exactly what kind of project you are doing, so these are just my recommendations.
I want to replace the default Django Admin templates with a completely revamped bootstrap version. The data in the Dashboard should be populated from the DB. How do I work with templated files ? Which files should be overriden ? In which template tag does HTML code go ?
From django docs on admin:
The admin’s recommended use is limited to an organization’s internal management tool. It’s not intended for building your entire front end around.
It's possible to change templates to do what you want, but that will be very complex - you have to basically rewrite most of the templates, get to know how it is working internally and probably change that too to your own design (after all, you are going to show specific details, like charts, data and so).
You will faster to achieve results if you going to build your own app, that will work exactly like you need without multiple fixes. Does it have to use js frameworks depends entirely on your requirements. Usually they are much more simple for admin backends, that are going to be used by owners, not clients. Anyway, if you don't have experience or knowledge in this, you will probably better off with just plain static django templates.
Django admin is just a same app as the ones you build, so limitations will be the same. Security wise, it doesn't offer much that you can't do yourself - make sure you have permissions set in models/views. Read more about security in django.
From functionality point of view, django admin just comes with CRUD access to your models, which can be done quite quickly. Once you past that, you will have much easier time adding functionality to your own app instead of overriding django admin.
Overall, I advise you to build your app for CMS-like admin panel. JS frameworks is neat, but that require burden of multiple additional tests (with api mocks), constant swapping between adding api / writing a component and much higher time consumption overall.
I am new to Django, but heard it was promising when attempting to create a a custom CMS.
I am looking to get started, but their seems to be a lack of documentation, tutorials, etc on how to actually get something like this going.
I am curious if their are any books/tutorials/guides that can help me get started with CMS django building.
PS- I have heard of django-cms, but am unsure what exactly it is and how it is different from django.
Here is a list of tutorials that has been put together by authors of Two Scoops of Django. http://twoscoopspress.com/pages/django-tutorials
django CMS is a CMS on top of django. It supports multiple languages really well and plays nice together with your own django apps. The basic idea is that you define placeholders in your template and then are able to fill those placeholders with content plugins. A content plugin can be a anything from text, picture, twitter stream, multi column layout etc.
You can look into this, it's about creating placeholder that can be replaced later, which is what CMS is, technically
https://docs.django-cms.org/en/latest/introduction/02-templates_placeholders.html
I'm new to Python and Django, but now have a pretty firm understanding of basic database and back end programming. However, I am finding it hard to learn the views and templates layers. I was wondering if anyone can suggest additional tutorials and resources, other than the official Django documentation.
I am also new to HTML, and am open to tutorials using Mako or Jinja2.
Thanks!
We've been using Mako+Django for almost two years on a large project, and it's been great. Mako is immensely better than the standard Django templates. Why on Earth would I want to learn another templating language when I already have to know Python, Javascript, HTML, JQuery, etc.? With Mako I can use regular Python, including all the libraries, in my HTML pages. And with Django integrated on the back end, the templates stay simple.
You might want to look at my Django+Mako starter kit. It does the templates the way I like to do them (not necessarily the standard way), but it is a project fully set up and ready to run. You can start from it and customize. http://warp.byu.edu/dist/django-mako.zip
Update: blog has moved to http://www.goalbrecht.com/2013/10/django-mako-plus-a-starter-kit/
and additional updates to the project are on Django-Mako-Plus' Github.
We use Mako in our workplace, and I highly recommend not using it. It's great for your own views, but if you want to use ANY third party libraries that include templates, they simply won't work.
Other than that, the official documentation, and googling for specific problems you're having is the best way to go when using django templating. Unfortunately, I can't comment on jinja templating.