How do I capture a part of sub-domain name and get that name as a string in my views through a request.
ex:
user.domain.com
developer.domain.com
I want to capture the user part of this domain name through a request (lets say when the first time user hits the page).
Thanks.
...
Hi,
I'm trying to change the default value of a foreignkey-formfield to set a Value of an other model depending on the logged in user.
But I'm racking my brain on it...
This: Changing ForeignKey’s defaults in admin site would an option to change the empty_label, but I need the default_value.
#Now I tried the following without errors b...
Quite often I need to filter some form data before using it (saving to database etc.) Let's say I want to strip whitespaces and replace repeating whitespaces with a single one in most of the text fields, in many forms. It's not difficult to do this using clean_<fieldname> methods:
# Simplified model with two text fields
class MyModel(mo...
I'm trying to configure logging for a Django app using the Python logging module. I have placed the following bit of configuration code in my Django project's settings.py file:
import logging
import logging.handlers
import os
date_fmt = '%m/%d/%Y %H:%M:%S'
log_formatter = logging.Formatter(u'[%(asctime)s] %(levelname)-7s: %(message)s (%...
Please post example code when request.POST contain query string in django, because i think my django version is bugged.
EDIT:
You simple can't, query string is always in GET, and this was my problem.
...
Here's my background:
Decent experience with PHP/MySql.
Beginner's experience with OOP
Why I want to learn Python Django?
I gave in, based on many searches on SO and reading over some of the answers, Python is a great, clean, and structured language to learn. And with the framework Django, it's easier to write codes that are shorter t...
If my model for Items is:
class Item(models.Model):
name = models.CharField(max_length=500)
startDate = models.DateField("Start Date", unique="true")
endDate = models.DateField("End Date")
Each Item needs to have a unique date range. for example, if i create an Item that has a date range of June 1st to June 8th, how ...
Django 1.2 allows usernames to take the form of an email address.
Changed in Django 1.2: Usernames may
now contain @, +, . and - characters
I know that's a much-requested feature, but what if you don't want the new behavior? It makes for messy usernames in profile URLs and seems to break django-registration (if a user registers a...
In my template I have this for loop:
{% for member in blog.members.all %}
{{ member.first_name }}
{% endfor %}
Is there a way to retrieve only the first 10 members and not all the members ?
...
Okay I just started with Django and it's totally different from PHP.
I installed Python 2.6 and Django.
Both are located in my C drive.
C:
Django
build
django
bin
django-admin.py
docs
Python26
I am doing the django site tutorial and when they say to write django-admin...
I have a BASE_DIR setting in my settings.py file:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
I need to use this variable in my logging.ini file to setup my file handler paths.
The initialization of logging happens in the same file, the settings.py file, below my BASE_DIR variable. Here I tell it the path of my logging.ini ...
yesterday, after I complete setup django-lfs without buildout.
Happlily create categories and products but while I upload image to
product after I push upload button its stay always 'pendings'. I use
fedora django==1.1.2,PIL==1.1.7. but its work on osx. Now I try on
Ubuntu9.10 with completely PIL==1.1.7 and Django==1.1.2 and its won't
wo...
i wonder if ruby on rails have bundles, the ones similar in django?
kind of a plugin that contains css, js, images, ruby code and everything for one feature.
thanks
...
I have a form for address information. One of the fields is for the address country. Currently this is just a textbox. I would like a drop down list (of ISO 3166 countries) for this. I'm a django newbie so I haven't even used a Django Select widget yet. What is a good way to do this?
Hard-code the choices in a file somewhere? Put ...
I've seen a few examples defining choice fields like so:
COUNTRIES = (
('fr', _('France')),
('de', _('Germany')),
...
)
(source: http://code.djangoproject.com/ticket/5446
Also see: http://djangosnippets.org/snippets/494/)
What is the meaning of the leading underscores? And why is the second value in the tuple even parent...
It's clear how to create a URLPattern which dispatches from a URL regex:
(r'^books/$', books),
where books can further dispatch on request method:
def books(request):
if request.method == 'POST':
...
else:
...
I'd like to know if there is an idiomatic way to include the request method inside the URLPattern, ...
I'm learning Python and decided to start familiarizing myself with the (defacto?) Python web framework - django.
I have successfully installed the latest release of django. I want a simple 'hello world' website that will get me up and running quickly. I am already familiar with web frameworks (albeit for different languages) - so I just...
Hi folks,
I'm finding this a bit tricky! Maybe someone can help me on this one
I have the following model:
class Unicorn(models.Model):
horn_length = models.IntegerField()
skin_color = models.CharField()
average_speed = models.IntegerField()
magical = models.BooleanField()
affinity = models.CharField()
I would like to sea...
Some advice needed on how I can structure my models for my site. I have seen this post from Django project but still a little lost.
Also come across Django-MPTT - but that's no help and possibly overkill.
I'm looking to have categories & subcategories that are shown in the URLs like this:
mysite.com/Level1/Maths/Calculations/Addition/...
Hi folks,
is there any way of doing the following
Unicorn.objects.or_filter(magical=True).or_filter(unicorn_length=15).or_filter(skin_color='White').or_filter(skin_color='Blue')
where or_filter stands for an isolated match
I remember using something similar but cannot find the function anymore!
Help would be great! Thanks :)
...