django-templates

TemplateDoesNotExist - file exists, no permissions issue

﹥>﹥吖頭↗ 提交于 2019-12-12 10:06:12
问题 I'm receiving this error when trying to render a template in django: TemplateDoesNotExist ... Template-loader postmortem Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: Here's my settings.py entry: SETTINGS_PATH = os.path.normpath(os.path.dirname(__file__)) TEMPLATE_DIRS = ( os.path.join(SETTINGS_PATH, 'template'), ) Here's my view that's being called: def handler(request)

How can I get the rendered output of a template within a template tag in django?

删除回忆录丶 提交于 2019-12-12 09:58:32
问题 Disclaimer: This is a follow on question from my previous question. I'm attempting to write a template tag in Django, that will render itself within the body of a Mako Template. I'm not sure that this is achievable, but it's something that'd be extremely useful to my project, and probably a lot of other people using Mako Templates within Django. Here is the definition of my tag: def extends_mako(parser, token): # wishlist below, this code does not work but it's what I want to achieve template

Customize Django admin template

核能气质少年 提交于 2019-12-12 09:54:56
问题 i tried customizing navbar like this Base_site.html {% block nav-global %} <img class = "brand_img" src = "{% static 'images/ic_launcher.png'%}" width = "50" height = "50" alt = "logo"> {%block branding%} {% endblock %} <div class = "head"> <h1 id = "name">Admin Dashboard</h1> </div> {% endblock %} which looks like this now i try to add header for login page inside {%block branding%} but if i add inside branding block it is displayed in navbar also and if i try to add both image and header in

Django: How to return to previous URL

假装没事ソ 提交于 2019-12-12 09:47:08
问题 Novice here who learned to develop a web app with python using Flask. Now I'm trying to learn django 1.9 by redoing the same app with django. Right now I am stuck at trying to get the current URL and pass it as an argument so that the user can come back once the action on the next page is completed. In Flask, to return to a previous URL, I would use the 'next' parameter and the request.url to get the current url before changing page. In the template you would find something like this: <a href

One url for two different views

守給你的承諾、 提交于 2019-12-12 09:25:56
问题 I'm developing a site that have two types of User, and the project's owners want two different home (templates) after the user is authenticated, so, I tried this: url # home a url(r'^home/$', HomeAView.as_view(), name='home-a'), # home b url(r'^home/$', HomeBView.as_view(), name='home-b'), And some like that at into my log_in view: if user.typeUser == "HA": print('Go to Home A') return redirect(reverse('sesion:home-a')) else: print('Go to Home B') return redirect(reverse('sesion:home-b')) So

Django login from in modal window

社会主义新天地 提交于 2019-12-12 08:13:12
问题 I have a login form and I want to put in modal window in header. Urls.py url(r'^account/login/$', appuser_views.LoginView.as_view(template_name = 'account/login/index.html', form_class = appuser_forms.LoginForm, target_url = LOGIN_TARGET_URL)), views.py class LoginView(ResendEmailToUsersMixin, AjaxFormView): def process_form(self, request, form): data = form.cleaned_data a = AppUserCredential.objects.select_related('appuser').filter( data1 = data['email_address'], credential_type =

Django Templates - Printing Comma-separated ManyToManyField, sorting results list into dict?

久未见 提交于 2019-12-12 07:56:29
问题 I have a Django project for managing a list of journal articles. The main model is Article . This has various fields to store things like title of the article, publication date, subject, as well as list of companies mentioned in the article. ( company is it's own model). I want a template that prints out a list of the articles, sorted by category, and also listing the companies mentioned. However, I'm hitting two issues. Firstly, the company field is a ManyToMany field. I'm printing this

Django templates: how to avoid empty lines with include and load?

橙三吉。 提交于 2019-12-12 07:53:58
问题 In a template, I use the following code: {% load i18n %} {% include "header.html" %} {% include "top_bar.html" %} But this produces several carriage returns ( \n ) as I separate every include and load by a carriage return. I don't want to concatenate inclusions like this: {% include "header.html" %}{% include "top_bar.html" %} Because it's unreadable. Is there a way to avoid these generated new lines ? 回答1: Well after some researches, I found this thread where a patch is submitted and

In Jinja2, how can I use macros in combination with block tags?

南笙酒味 提交于 2019-12-12 07:47:36
问题 I'm a front end developer, and I've been trying to get a hang on using Jinja2 effectively. I want to tweak a current site so it has multiple base templates using inheritance, it fully uses block tags to substitute content and override it, and uses macros to support passing of arguments. My base template contains this code (edited for simplicity): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> {% from "foo.html" import macro1, macro2, macro3 %} {%

Django - How to pass several arguments to the url template tag

一世执手 提交于 2019-12-12 07:41:00
问题 In my urls.py I have: (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/section/(?P<slug>[-\w]+)/$', 'paper.views.issue_section_detail', {}, 'paper_issue_section_detail' ), and I'm trying to do this in a template: {% url paper_issue_section_detail issue.pub_date.year,issue.pub_date.month,issue.pub_date.day,section_li.slug %} but I get this error: TemplateSyntaxError Caught an exception while rendering: Reverse for 'paper_issue_section_detail' with arguments '(2010, 1, 22, u'business')' and