Sunday, October 13, 2013
Republican Poll Numbers Reality
It's been reported (or spun) that the satisfaction with Republicans is at an all time low. Okay, I'll go along with that. I'm conservative and am dissatisfied with the Republicans, too. It's also been reported that it's because of the shutdown. This is where I believe that the US State Run Media is spinning the truth. What's the truth? It's simple.
Conservatives are dissatisfied with the Republicans because they are not being conservative enough. They continuously bend, cave and succumb to liberal tactics. They are hearing the intentional misinterpretations of the media. They hear the vial rhetoric of the liberals and of the Whitehouse. But, they do not seem to hear the voice of their base. Therefore, we are dissatisfied. But, we will be even more dissatisfied if they cave in again. Their poll numbers will improve if they take a strong stance and disregard the lies and spins from the left.
This is why average Americans like myself support the Tea Party. They are the voice of the American people. So, my advice to you Republicans, if you want to be re-elected (which seems to be all you care about), you need to be *MORE* Conservative, not less.
Friday, January 2, 2009
Configuring Mulitple Django Apps under one Project
Setting the Stage:
I have found Django to be rather daunting to configure and get set up. Being a Django newbie, bear in mind that there may be better ways or more secure ways. Advice from readers is welcome. The extent of my Django experience is that I've been through the Django tutorials. Enough disclaimer.
It took me awhile to draw the connection between my Apache configuration, my settings.py file, my urls.py file, the physical directory structure and the references to those files in code (templates and views).
Getting Started with the Pieces and the Problems:
I went through the tutorial on the Django site. So, I'm going to assume that you did, too. Otherwise, you might find this post quite confusing. As soon as I finished the tutorial, I wanted to try to set up another app for myself. I didn't want to start completely over either. Basically, I wanted to just add another app to my setup so that everything I had already done with the tutorial still worked (that way I could use it for reference), but my new app would work, too.
Identifying the pieces:
Let's look at some of the pieces. Some of the criteria in coming up with a configuration are that I wanted all of my templates grouped together, all of my apps in the same directory a static directory like a LAMP setup and the admin module should handle all of the apps in this project.
Assuming You have the Django Polls Tutorial Up and Running:
This is my physical filesystem layout. I'm not going to list every file, just the ones that are important for the discussion. Here, admin refers to the builtin Django app, app1 refers to the polls and app2 will refer to my new app:
/usr/local/www/django/prj_1/
settings.py
urls.py
/admin (the built in Django admin application)
admin.py
views.py
urls.py
/app1
admin.py
views.py
urls.py
/app2
admin.py
views.py
urls.py
/static
/admin
/media
/css
too many files to list here, they were copied from Django's builtin files
/common
/css
base.css
/templates
/admin
base_site.html
index.html
/common
app2_base.html
/app1
detail.html
index.html
results.html
vote.html
/app2
index.html
I use virtual directories with Apache. I'm not going to going too far into basic Apache configuration, though. Here's the configuration.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /usr/local/www/django/prj_1/static
ServerName mydomain.com
ServerAlias mydomain.com *.mydomain.com usmstudent
<Directory />
<Location "/">
<LocationMatch "\.(css|jpg|js)$">
</Virtualhost>
The relevant parts of the settings.py.
The urls.py:
I didn't do anything special in the urls.py files. They are just like the Django tutorial. So, I will refer you to that.
Referencing templates in code:
Putting it All Together:
Now, we have make sense of where everything lives, Now, it's time to see how you tell Django to find everything. I will list each thing that need to be located, then how it is resolved.
These are set by the PythonPath directive in Apache. The Django documentation explains that you have point it to the parent directory. I have two paths listed in my PythonPath, I suspect only one of them is necessary, but I haven't confirmed that yet.
static pages
This is set by the DocumentRoot directive in Apache. I have a css page that I reference in my base template with a relative path, like so:
<link rel="stylesheet" href="/common/css/base.css" type="text/css" />
So, if you append that to the DocumentRoot, you can find that in my file system.
One tricky thing to note here. The admin page looks in a specific location for its css content. In my case, I moved it to "/usr/local/www/django/prj_1/static/admin/media/css". So, if you combine my DocumentRoot, which is "/usr/local/www/django/prj_1/static/", with the "ADMIN_MEDIA_PREFIX" setting in the settings.py file, you get "/usr/local/www/django/prj_1/static/admin/media/". This will allow the builtin admin app to find the css files.
views
First, the PythonPath got us to the urls.py, the urls.py maps to views. This is one of the significant new concepts I'm still learning. With LAMP or plain html, you type a url in a browser, then Apache resolves it to a physical disk location. Now, when you type in a url, if it's in the PythonPath, Apache lets Python do what it wants to with it. In the case of Django, it hands it over to urls.py, then urls.py sends it to the appropriate view. The view then does any programming on it that it needs to do, then displays a template.
templates
Templates are named with an html extension. If you come from a LAMP background like me, you can get a little confused thinking your DocumentRoot will resolve these for you. But, Python handles this. It's easy enough to put use the TEMPLATE_DIRS directive in the settings.py file. Then, you will likely be referencing your templates inside your views. For example, my TEMPLATE_DIRS is set to '/usr/local/www/django/prj_1/templates'. In my views, when I want to reference a template, I imagine it being appended to that path. So, my index.html in "/usr/local/www/django/prj_1/templates/app2/index.html" is referenced by combining my TEMPLATE_DIRS and what I have coded in my view.py.
apps
Apps are pretty straight forward, they are resolved by the settings.py. You probably new that from going through the tutorial.
I have found Django to be rather daunting to configure and get set up. Being a Django newbie, bear in mind that there may be better ways or more secure ways. Advice from readers is welcome. The extent of my Django experience is that I've been through the Django tutorials. Enough disclaimer.
It took me awhile to draw the connection between my Apache configuration, my settings.py file, my urls.py file, the physical directory structure and the references to those files in code (templates and views).
Getting Started with the Pieces and the Problems:
I went through the tutorial on the Django site. So, I'm going to assume that you did, too. Otherwise, you might find this post quite confusing. As soon as I finished the tutorial, I wanted to try to set up another app for myself. I didn't want to start completely over either. Basically, I wanted to just add another app to my setup so that everything I had already done with the tutorial still worked (that way I could use it for reference), but my new app would work, too.
Identifying the pieces:
- settings.py
- urls.py
- Apache config
- physical directory layout
- references to templates, within other templates and views
Let's look at some of the pieces. Some of the criteria in coming up with a configuration are that I wanted all of my templates grouped together, all of my apps in the same directory a static directory like a LAMP setup and the admin module should handle all of the apps in this project.
Assuming You have the Django Polls Tutorial Up and Running:
This is my physical filesystem layout. I'm not going to list every file, just the ones that are important for the discussion. Here, admin refers to the builtin Django app, app1 refers to the polls and app2 will refer to my new app:
Show File Tree (+)
Hide File Tree (-)
/usr/local/www/django/prj_1/
settings.py
urls.py
/admin (the built in Django admin application)
admin.py
views.py
urls.py
/app1
admin.py
views.py
urls.py
/app2
admin.py
views.py
urls.py
/static
/admin
/media
/css
too many files to list here, they were copied from Django's builtin files
/common
/css
base.css
/templates
/admin
base_site.html
index.html
/common
app2_base.html
/app1
detail.html
index.html
results.html
vote.html
/app2
index.html
Show Apache Config (+)
Hide Apache Config (-)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /usr/local/www/django/prj_1/static
ServerName mydomain.com
ServerAlias mydomain.com *.mydomain.com usmstudent
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>AllowOverride All
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonDebug On
PythonPath "['/usr/local/www/django/', '/usr/local/www/django/prj_1/'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE prj_1.settings
</Location>PythonHandler django.core.handlers.modpython
PythonDebug On
PythonPath "['/usr/local/www/django/', '/usr/local/www/django/prj_1/'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE prj_1.settings
<LocationMatch "\.(css|jpg|js)$">
SetHandler None
</LocationMatch></Virtualhost>
The relevant parts of the settings.py.
Show Settings.py (+)
Hide Settings.py (-)
ADMIN_MEDIA_PREFIX = '/admin/media/'
TEMPLATE_DIRS = (
'/usr/local/www/django/prj_1/templates',
)INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'prj_1.app1',
'prj_1.app2',
'django.contrib.admin'
)'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'prj_1.app1',
'prj_1.app2',
'django.contrib.admin'
The urls.py:
I didn't do anything special in the urls.py files. They are just like the Django tutorial. So, I will refer you to that.
Referencing templates in code:
So far, I'm just working on the templates for my app2 (my new app). And, I only have a base template and one that inherits from it. The point I'd like to make is how Django finds them, not how the templating system works.
As pointed out in the filesystem layout above, my app2 base template is in /usr/local/www/django/prj_1/templates/common/base.html. My template located at /usr/local/www/django/prj_1/templates/app2/index.html, refers to it as such:
We're ready now, to put some of this together. But, I'll do it all at once in the next section.
As pointed out in the filesystem layout above, my app2 base template is in /usr/local/www/django/prj_1/templates/common/base.html. My template located at /usr/local/www/django/prj_1/templates/app2/index.html, refers to it as such:
{% extends "common/base.html" %}
We're ready now, to put some of this together. But, I'll do it all at once in the next section.
Putting it All Together:
Now, we have make sense of where everything lives, Now, it's time to see how you tell Django to find everything. I will list each thing that need to be located, then how it is resolved.
- the settings.py and urls.py
- the static pages
- the views
- the templates
- the apps
These are set by the PythonPath directive in Apache. The Django documentation explains that you have point it to the parent directory. I have two paths listed in my PythonPath, I suspect only one of them is necessary, but I haven't confirmed that yet.
static pages
This is set by the DocumentRoot directive in Apache. I have a css page that I reference in my base template with a relative path, like so:
<link rel="stylesheet" href="/common/css/base.css" type="text/css" />
So, if you append that to the DocumentRoot, you can find that in my file system.
One tricky thing to note here. The admin page looks in a specific location for its css content. In my case, I moved it to "/usr/local/www/django/prj_1/static/admin/media/css". So, if you combine my DocumentRoot, which is "/usr/local/www/django/prj_1/static/", with the "ADMIN_MEDIA_PREFIX" setting in the settings.py file, you get "/usr/local/www/django/prj_1/static/admin/media/". This will allow the builtin admin app to find the css files.
views
First, the PythonPath got us to the urls.py, the urls.py maps to views. This is one of the significant new concepts I'm still learning. With LAMP or plain html, you type a url in a browser, then Apache resolves it to a physical disk location. Now, when you type in a url, if it's in the PythonPath, Apache lets Python do what it wants to with it. In the case of Django, it hands it over to urls.py, then urls.py sends it to the appropriate view. The view then does any programming on it that it needs to do, then displays a template.
templates
Templates are named with an html extension. If you come from a LAMP background like me, you can get a little confused thinking your DocumentRoot will resolve these for you. But, Python handles this. It's easy enough to put use the TEMPLATE_DIRS directive in the settings.py file. Then, you will likely be referencing your templates inside your views. For example, my TEMPLATE_DIRS is set to '/usr/local/www/django/prj_1/templates'. In my views, when I want to reference a template, I imagine it being appended to that path. So, my index.html in "/usr/local/www/django/prj_1/templates/app2/index.html" is referenced by combining my TEMPLATE_DIRS and what I have coded in my view.py.
apps
Apps are pretty straight forward, they are resolved by the settings.py. You probably new that from going through the tutorial.
Subscribe to:
Posts (Atom)