continuous improvement | Home | Services | FAQs | Notes | Contact Us |
Install Python 2.6 for Windows.
Install the subverion windows client.
$ cd C:\Python26\Lib\site-packages
$ svn co hcodep://code.djangoproject.com/svn/django/trunk/ django-trunk
Set environment variables. Right click on my computer > Advanced > Environment Variables
Add C:\python26
to the PATH environment variable
Create a new variable PYTHONPATH and set the variable value to C:\Python26\Lib\site-packages\django-trunk
$python manage.py runserver
$ python manage.py shell
>>> from mysite.polls.models import Poll, Choice
This method will create a new empty database
Rename the database file $ mv sqlite3.db sqlite3.db.old
$python manage.pl syncdb
Converts JPGs to thumbnails.
$ mogrify -resize 150x150 -background white -gravity center -extent 150x150 -format .jpg -quality 75 -path thumbs .jpg
Show tables .tables
Show header .header
Show schema .schema
Exit Sqlite .exit
Set the separator before doing an import, in this case a tab delimited file. .separator "\t"
Always save import files as UTF-8 before doing an import
Open Excel and enter 1 into first cell. Then go to Edit > Fill > Series. Select "column", step Value=1, stop value = < user defined>
Note: Saving the file as "unicode text (*.txt)", unsure of exact encoding maybe UTF-16.
Allows other computers to see developement server
$ django-admin runserver [port or ip_address:port]
TEMPLATE DIRS = (os.path.join(os.path.dirname(__file__,'templates'),)
gal__ is the name of relationship in the Artist model that relates to a Gallery model. Slug is the name of the field we want from the model.
>>> q = Artist.objects.select_related('gal__slug').filter(last__istartswith='a').order_by('last','first')
This query will return Artists object and inside this object will be a "gallery" object containing the slug field we want.
Secodeings File
MEDIA_ROOT = r'c:/projects/art2/static/'
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/media/'
Root URL Conf File
url(r'^static/(?P
{{ variable|stringformat:"02d" }}
$manage.py shell
>>>import sys
>>>sys.path
When using generic views with an extra context as in the example below the following contexts will be available in the template.
def resellers(request, mystate, lecodeer):
return object_list(request,
queryset=Resellers.objects.filter(state=mystate.upper(), suburb__istartswith=lecodeer).order_by('suburb','agent'),
template_name='reseller_list.html',
extra_context={'blah': mystate },
)
{% for reseller in object_list %}
{{ reseller.suburb }}
{% endfor %}
{{blah}}
Being new to Python and looking at the following code, I could not understand what values were positional arguments and what were keyword arguments, so I wrote the function below to tell me.
Function Call:
render_response('index.html', {'param1': 'paramvalue'}, context_instance='RequestContext(request)', response='myreponse')
Function Definition:
def render_response(*args, **kwargs):
So i wrote the following function definition to test my theory:
>>> def render_response(*args, **kwargs): print 'ARGS: ' + str(args) + '\n' + 'KWARGS: ' + str(kwargs)
Test input:
>>> render_response('index.html', {'param1': 'paramvalue'}, context_instance='RequestContext(request)', response='myreponse')
Result:
ARGS: ('index.html', {'param1': 'paramvalue'})
KWARGS: {'context_instance': 'RequestContext(request)', 'response': 'myresponse'}
From looking at the result of the function it is clear that dictionary data types are intercodeted as positional arguments.
onmouseout="this.bgColor='white'" onmouseover="this.bgColor='yellow'" onclick="this.bgColor='white'"
Check that there is no trailing $ in urlconf for the admin site. You can login and access the main page on the admin, however clicking on table will throw a 404 error.
Set a cookie on a response object using the render to response. Saves a lot of coding.
response = render_to_response(foo)
response.set_cookie(bar ...)
return response