django-templates

Django email message as HTML

核能气质少年 提交于 2019-12-06 05:00:13
I have an email template that I use to send emails of different kinds. I'd rather not keep multiple email HTML templates, so the best way to handle this is to customize the message contents. Like so: def email_form(request): html_message = loader.render_to_string( 'register/email-template.html', { 'hero': 'email_hero.png', 'message': 'We\'ll be contacting you shortly! If you have any questions, you can contact us at <a href="#">meow@something.com</a>', 'from_email': 'lala@lala.com', } ) email_subject = 'Thank you for your beeswax!' to_list = 'johndoe@whatever.com' send_mail(email_subject,

Can I create sub domain for each user in Django

只谈情不闲聊 提交于 2019-12-06 04:51:46
问题 I want users create their own account and users should get their own like user.foo.com and different point to different template folder. Is it possible in Django. I quite new to Django 回答1: Django itself is unaware of whatever web server you are using. Usually, to configure extra sub-domains, you need to add virtual hosts to your webserver's configuration and make sure your DNS provider forwards requests for that sub-domain to the appropriate server. To do this directly, you'll need to run

Django template with jquery: Ajax update on existing page

。_饼干妹妹 提交于 2019-12-06 03:40:12
I have a Google App Engine that has a form. When the user clicks on the submit button, AJAX operation will be called, and the server will output something to append to the end of the very page where it comes from. How, I have a Django template, and I intend to use jquery. I have the following view: <html> <head> <title></title> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/scripts.js"></script> </head> <body> welcome <form id="SubmitForm" action="/" method="POST"> <input type="file" name="vsprojFiles" /> <br/> <input type="submit"

Converting a nested dictionary to a list

社会主义新天地 提交于 2019-12-06 03:07:03
问题 I know there are many dict to list questions on here but I can't quite find the information I need for my situation so I'm asking a new quetion. Some background: I'm using a hierarchical package for my models and the built-in function which generates the tree structure outputs a nested loop to indicate parents, children, etc. My goal is to keep the logic in views and output a list so that I can simply loop over it in my templates. Here is my data, in the tree structure: 1 -1.1 --1.1.1 ---1.1

Django 1.11 404 Page while Debug=True

≡放荡痞女 提交于 2019-12-06 02:31:41
Without making things difficult , I just want to show a special 404 render with staticfiles. If you set DEBUG = False you can use in urls.py handler404 = 'app.views.handler404' But it is without staticfiles. I don't want to install a web server for a simple app. With DEBUG = True in urls url(r'^404/$', views.handler400) is not overriding the default Page not found (404) page. What is the easy way to achieve a render e.g. when you type localhost/asdfhjfsda with staticfiles when DEBUG=True ? Thanks in advance... In django 1.10 docs : Changed in Django 1.9: The signature of page_not_found()

Interpolate Django template include variable

淺唱寂寞╮ 提交于 2019-12-06 02:13:50
I'm doing something like {% for part in parts %} {% include "inc.html" with o=part prefix="part{{ forloop.counter0 }}_" %} {% endfor %} where inc.html could be something of such kind: <p id="{{ prefix }}para">{{ o.text }}</p> I just discovered the prefix variable isn't interpolated and "part{{ forloop.counter0 }}_" is passed literally. Any relatively elegant work-around? I think the best solution would be to register an inclusion_tag, that would handle the part and forloop.counter operations: @register.inclusion_tag("inc.html") def inc_tag(part, loop_counter): prefix = 'part%s_' % (loop

Localization with django and xgettext

偶尔善良 提交于 2019-12-06 02:13:17
I am working on translation of my site, but when I try to run command: manage.py makemessages --locale=bs I constantly get error like: CommandError: errors happened while running xgettext on rjsmin.py xgettext: Non-ASCII string at .\compressor\filters\jsmin\rjsmin.py:59. Please specify the source encoding through --from-code. What shell I do? I have the same problem. At the top of the rjsmin.py, change the "- * - coding: ascii -*-" to "- * - coding: utf-8 - * -" 来源: https://stackoverflow.com/questions/20955811/localization-with-django-and-xgettext

Django: How to return to previous URL

徘徊边缘 提交于 2019-12-06 02:10:14
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="{{ url_for('.add_punchcard', id=user.id, next=request.url) }}">Buy punchcard :</a> and in the view:

Django Static js files not working

不羁岁月 提交于 2019-12-06 02:02:05
Well my template code. <!DOCTYPE html> <html> <head> {% load staticfiles %} <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript" src="{% static 'website/staffaddproblem.js' %}"></script> <title>Dashboard</title> <link href="{% static 'website/style.css' %}" rel="stylesheet" type="text/css"/> </head> <body> body </body> <html> As you can see it has a css file. which is working properly, but java script file does not work. when i load the page its source looks like this. When i click the link it loads the file too its there its

Django Admin: using different templates for two admin site

爱⌒轻易说出口 提交于 2019-12-06 01:54:02
问题 I've a Django project with two different admin-site (as described in documentation ) I would like to have different custom template for each of them. I know how to override custom template, by putting html files in myproject/templates/admin/ directory. However, both admin-site use those templates ! I don't understand how to specify another set of custom templates. Ideally, I would like having: # For first admin site myproject/templates/admin-a/ base.html base_site.html and: # For second admin