django-templates

What/Where to modify django-registration to use with mobile broswers

假如想象 提交于 2019-12-04 10:56:10
I am using django-registration along side django auth for my client account creation and login. Our site will be used by moble users and desktop users. We just started tackling the idea of mobile users by loading different templates from the view depending on user agent strings. It's cleanly done, but I am not sure if it is the right way to do it as we are now stuck with what to do on views that are not easily accessible (that we didn't write ourselves). Which brings me to the problem at hand: I have no idea how to tackle redirecting the mobile user away from the login url that django

How do I access template cache? - Django

淺唱寂寞╮ 提交于 2019-12-04 10:52:49
问题 I am caching html within a few templates e.g.: {% cache 900 stats %} {{ stats }} {% endcache %} Can I access the cache using the low level library? e.g. html = cache.get('stats') I really need to have some fine-grained control over the template caching :) Any ideas? Thanks everyone! :D 回答1: This is how I access the template cache in my project: from django.utils.hashcompat import md5_constructor from django.utils.http import urlquote def someView(request): variables = [var1, var2, var3] hash

How to redirect users to a specific url after registration in django registration?

爷,独闯天下 提交于 2019-12-04 10:51:52
问题 So I am using django-registration app to implement a user registration page for my site. I used Django's backends.simple views which allows the users to immediately login after registration. My question is how do I redirect them to my other app's page located in the same directory as the project. Here is what my main urls.py looks like: from django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: # from django.contrib import admin # admin

How to use Django ORM to get a list by year of all articles with an article count

白昼怎懂夜的黑 提交于 2019-12-04 10:09:08
I am trying use the django ORM to get a list by year of all my articles with an article count beside it, such as this: 2010 (5 articles) 2009 (4 articles) 2008 (9 articles) I have tried things such as: archive = Articles.objects.dates('created', 'year').annotate(archive_count=Count('created')) or: archive = Articles.objects.values('created').annotate(archive_count=Count('created')) or: archive = Articles.objects.values('created').aggregate(archive_count=Count('created')) The last one gave me the right count but didn't give me any of the year values, the other ones give a mix of either nothing

Can I create sub domain for each user in Django

别说谁变了你拦得住时间么 提交于 2019-12-04 10:08:43
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 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 under a user account that has write access to your webserver's configuration file, which is really not

How to disable HTML encoding when using Context in django

无人久伴 提交于 2019-12-04 09:05:04
问题 In my django application I am using a template to construct email body, one of the parameters is url, note there are two parametes separated by ampersand in the url. t = loader.get_template("sometemplate") c = Context({ 'foo': 'bar', 'url': 'http://127.0.0.1/test?a=1&b=2', }) print t.render(c) After rendering it produces: http://127.0.0.1/test?a=1&b=2 Note the ampersand is HTML encoded as "&". One way around the problem is to pass each parameter separately to my template and construct the

Django Templates - Changing context for an 'include' template

徘徊边缘 提交于 2019-12-04 09:01:26
问题 I have a template that includes several tables. I want to use a sub-template which renders these tables in the same way. I can get it to work for a single table, by setting the context in the view and passing that to the template. But how do you change the data for to render another table for different data? **'myview.py'** from django.shortcuts import render_to_response table_header = ("First Title", "Second Title") table_data = (("Line1","Data01","Data02"), ("Line2","Data03","Data03"))

Django query to get User's favorite posts?

≯℡__Kan透↙ 提交于 2019-12-04 09:00:45
I'm a little confused by the Django lingo. So I have 3 models: Post, UserProfile(User), Favorite. Favorite keeps track of which Posts a User has favorited. Post--->Favorite<---User/UserProfile Favorite model: class Favorite(models.Model): user = models.ForeignKey(User, unique=False) post = models.ForeignKey(Post, unique=False) def __unicode__(self): return self.user.username UserProfile model: class UserProfile(models.Model) : user = models.ForeignKey(User, unique=True) def get_favorites(self): if self.user: return self.user.favorite_set.all() In my post_list view I pass all Posts to my

Django setting for default template tag output when variable is None?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 08:18:10
问题 I am looking for a django setting or programmatic way to make all django template tags show the empty string when the value is None. For example, imagine that I have some django template: {{cat}} chases {{mouse}} if both cat and mouse are None, it will render as: None chases None I am aware that I can set each one using {{cat|default:""}} or {{mouse|default_if_none:""}} However, I am looking for some sort of setting that would allow me to set the default for all tags, without explicitly

How do I display a PIL Image object in a template?

强颜欢笑 提交于 2019-12-04 08:09:16
问题 If a user uploads an image, and I resize it using PIL, I get a PIL Image object. How do I display a PIL Image file in a template, before it has been saved to the database? Can it even be passed in as an image and rendered? 回答1: For a limited set of browsers, you can base64 encode the image and use inline images. See Embedding Base64 Images. A solution that works for all browsers is an image tag referencing a view that returns the image. [update] All I want is for the user to submit the