I'd like to be able to instantiate a template from a file (presumably using the django.template.loader.get_template(filename) ), and then determine the set of variables that should be defined in whatever context it is passed.
I thought there would be a method on the Template object, but there doesn't seem to be.
I read the docs, and t...
I learned how to authenticate users in Django months ago, but I've since upgraded and am having some problems so it occurred to me this morning that I may not have been doing it correctly from the start so I decided to ask.
In my project's urls.py file I've got ^accounts/login/$ and ^accounts/logout/$ both wired up to the built-in login...
Just experienced a very strange error on our production server on all
page requests.
FieldError: Cannot resolve keyword 'session_key' into field. Choices
are: expire_date, session_data, session_key
The error persisted for about 10 minutes until a graceful restart of
apache2 was done.
I couldn't find anything online regarding Dja...
I have a big Django project with several interrelated projects and a lot of caching in use. It currently has a file which stores cache helper functions. So for example, get_object_x(id) would check cache for this object and if it wasn't there, go to the DB and pull it from there and return it, caching it along the way. This same pattern ...
I'm suddenly running into an issue where docstring tests like this:
"""
>>> g = 5
>>> g
5
"""
Would run and look like this:
...
Installing Index for ModeName
....
5...
Failed example:
g
Expected:
5
Got nothing
In short, it's printing out the expected results instead of returning them! What would cause something like...
Consider the following setup:
urls.py
if not settings.PRODUCTION:
urlpatterns += patterns('',
(r'^admin-media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.LOCAL_ADMIN_MEDIA_ROOT, 'show_indexes': True}),
(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.LOCAL_M...
I'd like to group records in two categories:
Items having three or more records
Items having less than three items
How do I go about this? I'm looking at using annotate().
...
How to get all table names in a Django app?
I use the following code but it doesn't get the tables created by ManyToManyField
from django.db.models import get_app, get_models
app = get_app(app_name)
for model in get_models(app):
print model._meta.db_table
...
I'm trying to create a file dynamically in Django:
response = HttpResponse(mimetype='text/txt')
response['Content-Disposition'] = 'attachment; filename=%s' % filename # UnicodeEncodeError
response.write('text')
return response
If I hardcode the filename it works properly, but if I try to create the filename from DB data that contain...
My Django-Project is making some strange faned-out GET calls when opening on model from the admin-site and i have no idea where this comes from. I will try to provide as much information possible.
Imagine this model called 'Rating', which holds a reference i.e. foreign key to 'Item', 'Usecase' and 'Rater'. So the Item can be rated under...
I have some custom render_to_response methods which now needs request object, I could pass request to each one of them but instead I am saving request object in a middleware to thread local space and accessing it elsewhere, can it affect me anyway?
...
Hi
I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing..
I then have a user inputting some text into a form ...
Here is my URL pattern:
news_info_month_dict = {
'queryset': Entry.published.filter(is_published=True),
'date_field': 'pub_date',
'month_format': '%m',
}
and
(r'^(?P<category>[-\w]+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+).html$',
'object_detail', news_info_month_dict, 'news_detail'),
But t...
I have a template filter that performs a very simple task and works well, but I would like to use a decorator on it. Unfortunately the decorator causes a nasty django error that doesn't make any sense...
Code that works:
@register.filter(name="has_network")
def has_network(profile, network):
hasnetworkfunc = getattr(profile, "has_%...
I have a simple database in django with SQLite and now I want to improve it with a better search capability (I will create a new project with new models). I would like to ask about how to plan and go about this project. The existing database has these fields
first, initial, last, school, yearGraduated
I am using django admin to sor...
I'm rolling a custom comment app that can take any object and allow the user to post comments (much like the one that comes with django.contrib).
My first thought, since none of the form is specific to any particular view, was to put it in a template tag:
@register.inclusion_tag('comments/add.html', takes_context=True)
def add_comment(...
In Django login, we see a variable called "next" to redirect to the next page after login. How to control this variable?
...
I have a model "Messages" which i use to store messages throughout the site. These are messages in discussions, private messages and probably chat. They are all stored in 1 table. I wonder if it will be faster if i spread messages among several models and tables. 1 for chat, one for discussions and so on.
So should i keep all message...
I have this decorator, used to decorate a django view when I do not want the view to be executed if the share argument is True (handled by middleware)
class no_share(object):
def __init__(self, view):
self.view = view
def __call__(self, request, *args, **kwargs):
"""Don't let them in if it's shared"""
i...
One of my template tags should return a list of links; most of the elements get their name from the database with the exception of one, which I'll hardcode because it will never change.
lista_menu = '<ul class="menu">\n\
<li><a href="' + reverse('profileloja', args=(s_loja,)) + '">' + \
loja.nome.title() + '</a></li>\n<li><a href="' + r...