This particular example relates to Django in Python, but should apply to any language supporting exceptions:
try:
object = ModelClass.objects.get(search=value)
except DoesNotExist:
pass
if object:
# do stuff
The Django model class provides a simple method get which allows me to search for one and only one object from the ...
I'm working on a Django-based application in a corporate environment and would like to use the existing Active Directory system for authentication of users (so they don't get yet another login/password combo). I would also like to continue to use Django's user authorization / permission system to manage user capabilities.
Does anyone h...
We have a website made by Django. And there is no problem when access
following url on local working environment:
http://site/tags/c%23/
"c%23" is urlencode of "c#", that works fine locally.
But after we deploy it on Bluehost hosting server (apache+fastcgi), this URL has been resolved to a new address like this:
http://site/t/tag...
Hello,
Is it possible to have a variable number of fields using django forms?
The specific application is this:
A user can upload as many pictures as they want on the image upload form. Once the pictures are uploaded they are taken to a page where they can give the pictures a name and description. The number of pictures will depend on...
Is there a way of doing the following?
model = "User"
model.objects.all()
...as opposed to User.objects.all().
EDIT: I am trying to make this call based on command-line input. Is it possible to avoid the import statement, e.g.,
model = django.authx.models.User
? Django returns an error, "global name django is not defined."
...
Hi all,
I am trying to port my first Django 1.0.2 application to run on OSX/Leopard with Apache + mod_python 3.3.1 + python 2.6.1 (all running in 64-bit mode) and I am experiencing an occasional error when uploading a file that was not present when testing with the Django development server.
The code for the upload is similar to what ...
Can anyone please suggest me some good testing tools for a django project? I need to test the different use case scenarios, unit testing, as well as load testing for my project. Is there any good standard testing suite available?? Any other suggestion(s) for the testing process is greatly appreciated. I use Django, postgresql on Ubuntu s...
I have a model Question with a field called userid, before one ask a question, one needs to login, i want when saving to capture the user ID of the currently logged-in user and assign it to the userid of the Question model.
Please note am not showing the userid on my form i.e. in the Question model i have declared the userid as follows;...
I am using the Python, Django framework and PostgreSQL combination. I am using the full text search of PostgreSQL (8.3) and am overriding the default filter function of Manager class in Django. Using the link: http://barryp.org/blog/entries/postgresql-full-text-search-django/ I was able to configure my full text search, as mentioned in t...
I need to store some values in the database, distance, weight etc. In my model, i have field that contains quantity of something and IntegerField whith choices option, that determines what this quantity means(length, time duration etc). Should i create model for units and physical quantity or should i use IntegerField that contains type ...
Hi, I am trying to make a livesearch with Django and jQuery. What I've done is make the javascript ask for some data with the getJSON function, then I've set up a view in Django that returns a JSON response automated by the Django serializer.
And this works well, it returns a json response with the text/javascript content-type. To avoid...
I use Django for my website and I want to know whether there is a work around for testing secure pages in Development server. As a temporary workaround, I wont use HTTP to check the webpages in dev server, which I think is not a correct way? What do you think?
...
I have a django model (schedule) with the class of entity, that is the parent of activity, that is the parent of event.
class Entity(models.Model):
<...>
class Activity(models.Model):
<...>
team_entity = models.ForeignKey(Entity)
<...>
class Event(models.Model):
<...>
activity = models.ForeignKey(Activity)
...
I need some way to add a class attribute to the output of the label_tag() method for a forms field.
I see that there is the ability to pass in an attrs dictionary and I have tested it in the shell and I can do something like:
for field in form:
print field.label_tag(attrs{'class':'Foo'})
I will see the class='Foo' in my output, ...
I am working on a Django application which contains an Offer model. An Offer instance contains the pricing conditions and points to a product definition. The product model is actually a hierarchy (I have a Television model, a Camcorder model, etc.). So I would like the Offer model to contain a polymorphic (or "generic") association to...
I often see something like that:
something.property|escape
something is an object, property is it's string property. escape - i don't know :)
What does this mean? And what min python version it is used in?
EDIT: The question was asked wrongly, it said "What does | mean in Python", so the bitwise or answers are correct, but irrelevan...
I am running Django trunk and have template Autoescaping on (default). Do I need to pass template URLs to the URLENCODE filter, or does Autoescape take care of that automatically? The Django docs aren't clear.
Django docs say this about Autoescape:
When auto-escaping is in effect, all variable content has HTML escaping applied to it...
Am using django framework, am pretty comfortable with the backend logic using python, but whats bothering me is the front-end bit where i have to work with css, how can i learn easily the workings of css or is there a tool i can use to create the front-end interfaces for django easily?
...
I am using the django framework and am using templates, inheriting a lot of admin base templates. What am wondering is: can I have more than one CSS file in one HTML file? i.e. maintain the django admin CSS file but then have another CSS file of my own with different styles!
...
After reading the Jinja2 documentation, I'm interested in employing it in future Django projects. However, I'm wondering if anyone has encountered any drawbacks or gotchas when using Jinja2 templates with Django? If so, how did you work around them?
I wouldn't mind hearing about positive experiences either, just to get a good cross se...