TemplateNotFound: theme_base.html - python

I'm trying to set up a webpage, and one of my html files begins with {% extends "theme_base.html" %}. When I try to run the program, I get an error message saying "TemplateDoesNotExist" for theme_base.html. I don't think this is a file that I have to create. Is there something I need to install to access this html file? I've already got pinax_theme_bootstrap installed. I thought that that was what I needed, but the error is still there.

Usually with Django, websites have a base theme, which other pages use to display content so you don't have to recode things like the header and footer. This is the basis of most front-end frameworks.
The question is, why does your HTML file extend a base template that doesn't exist? It sounds like you're trying to alter pieces of a project without the underlying files to the project.
The django docs are really great, and if you're new to django going through their quick tutorials will help you substantially:
https://www.djangoproject.com/start/

Related

creating multi-lingual website using django

I am creating a website from scratch where I am planning to make it dynamically multilingual. Tools I use are:
MongoDB for my database (atlas)
pymongo to connect to DB
django as my framework env
My idea is to have a website that can have multiple languages as necessary. languages can be RTL and LTR. I can add any language in a form of json file that has an item against its translation to the desired language, for instance english-french json file would be:
{"door":"porte"}
{"direction": "LTR"}
by adding such a file my website should be able to have the right information regarding the french language for instance and everything should appear in french correctly as specified in the json file. I plan to have two types of html pages in my DB for each of my website pages; one for "RTL" and one for "LTR", I render them based on the request of the user. (language chosen in the front end). In translation process, after picking the right orientation of the language, I use django template variables in my html to place the right language using the correct json file of the language, all my json files are stored in the database, and retrieved by the desired lanaguge chosen by the user.
I have couple of questions:
Am I thinking in the right direction?! or I am re-inventing the wheel and there are other tools that does the job for me?!
Is there a best practice for international websites?!
Is there any tool that can help does that more easily?
any suggestions or comments is highly appreciated.
Thank you
You are definitely re-inventing the wheel. Django already comes with i18n support.
This works for nearly all elements.
As described here:
https://docs.djangoproject.com/en/3.1/topics/i18n/
I personally would recommend using gettext_lazy() as it makes things easier, but that's just my taste.
There is of course also a template tag called {% trans "Whatever" %}
You will end up with text files that you can simply edit and also use SaaS if you want a fancy user interface.

Django Editable Text Field

I've been able to easily create a list of editable items and manage them through the Django admin panel. That seems pretty simple and I have a good idea of how models work from other frameworks.
Although, I'm curious to know to know how I can make something as simple as editing a text area on a static site. Basically, I don't need to "add post" or anything of the sort. I just want to be able to edit a text area on a static site.
Any docs or examples?
I've been looking at packages such as django-flatblocks and chunks, these seem to possibly help with what I'd like to do. I'm just new to the Python world so some of this stuff is a little magic to me, especially involving the administration panel.
One thing that I realized is that these libraries (or apps in django?) seem to be super out of date, stemming back to the last commit being from 2012. Are these still commonly used?
Figured out a solution in case anyone is interested. I ended up using a Django application called django-generic-flatblocks which seems to provide me with what I need. Although, it's a bit strange as I had to replace all the text on my site with a gblock and then re-enter it all. Seems as if upon first creation of a block, it's empty so you essentially have to provide it with a value.
After that, if you log into the admin panel you're able to pull up the block and edit it. Alternatively, if you're logged into the Admin panel you're able to view your site and an edit tag is provided and you'll go directly to that block in the admin panel.
If anyone knows of anything which essentially allows me to define the text blocks up front in the admin panel then add the tags to the code, please lmk. I'd prefer to load all my content into the admin panel first and then just throw the tag into the code and have it display. That would save a lot of time in terms of having to copy the existing content, store it away, adding the tag, and then having to put it back in.
This seemed to be the only one of the recommended apps that worked for me. I tried to use Chunks because this really is only for title/text but on Django 1.11 it would freak out on me about not having South.db, which isn't even used.
https://github.com/bartTC/django-generic-flatblocks

Loading an external template in GAE application?

Is there a way to load a template from a source which is not hosted on the application itself? For example, in order to load a template on the application itself (hosted by the appengine app):
html = template.render("admin/my_template.html", params)
I would like to do something like:
html = template.render("http://www.otherhost.com/external_template.html", params)
Is there a mechanism to allow such a behavior?
Thanks
Ofcourse you can load templates from other apps. To load templates you have to fetch the templates.
But using an editor is also not very difficult. I use codemirror to edit a HTML textarea.
See this list of demos : http://codemirror.net/demo/
Editing a Jinja txt mail template example:
Templates are just strings. If you can get the text, you can parse it as a template.
In this case you would need to make a request for the file using urllib, get the response, and then use template.Template(content) to convert it to a template object.
However, I must say I still think keeping it in the datastore is a better bet. I'm not sure why you would need an editor for that - why not just cut and paste the content into a field in the GAE admin console, or using the remote API to set it?

Django - Managing page content in Django Admin

I'm new to working with Django and am developing for a client who wants to be able to change page content in the Django Admin. They need to be able to change the html of the index page without editing the files on the server.
I know about flatfiles but I'm not sure that's completely what I'm after as I can't display stuff such as Django forms for example.
EDIT: Kind of like how a CMS works but without the users/group stuff and be able to use Django View modules such as forms.
Any advice?
Thanks
Honestly, the scope of what you're looking for is too huge to cover in this format. There's a number of ways this could be done, but they're all going to require some work and customization based on the client's needs.
Flatpages could work if you allow HTML content and make sure the content is rendered as "safe" in the template. This really only covers the "content" area of the site, though. It wouldn't be wise to use flatpages for an entire site template, including header, sidebar, footer, etc.
You could create editable areas. So, you actually create models for things like headers, sidebars, footers, and modules within those areas, and then just pull them into the template as needed. Then, the client is only editing pieces of the template instead of responsible for the whole HTML document.
Forms are going to be a challenge, because they require backend-processing that requires a connected view. The client won't be able to just arbitrarily drop in some form code and have a form. But, you could use a third-party service form forms and just embed them in the available content regions. Or, there's a couple of django apps that try to implement a type of "form builder" in the admin. That might somehow let the client add a form via something like the shortcodes used in Wordpress, but you'd likely have to lay down some infrastructure to make that work.
At a certain point, stuff like this reaches a point of diminishing returns, though. The only way to allow total customization of the template is to drop down into the actual physical file and make changes there. You can make certain things easier for the client, but ultimately, they either need to scale back their customization needs or deal with the fact that they'll have to work with the filesystem.
I don't believe that is possible at this time. Of course you can edit your models but templates, I think not.
I would find out how much they need to change? If they plan a complete redesign every week then you're still looking for an answer. If they just need a dynamic front page then you can split it up into variables and let them edit sections of html. Much safer and less prone to breaking the html.

'Snippit' based django semi-CMS

I remember reading somewhere on the internets about a half-assed tiny django CMS app, which was basically built on 'snippets' of text.
The idea was, that in the admin, you make a snippet (say a description of a product), give it a name (such as 'google_desc') and call it in a template with something like {% snippet google_desc %} and bam!
I think it was this guy that made it, but im not quite sure.
Would anyone know where i could find this piece of awesomeness?
Edit: I was after an app or something to plug into my project. Not, an existing website/service.
Edit 2: insin got it. I was after django-chunks
Sounds like django-chunks to me.
Are you talking about Django Simplepages? Official site here.
Another project that sounds similar to what you're after is django-page-cms.
If you need some more features just checkout django-blocks (http://code.google.com/p/django-blocks/). Has multi-language Menu, Flatpages and even has a simple Shopping Cart!!

Categories