tag:blogger.com,1999:blog-1019729307017543502024-02-20T04:27:50.026-08:00Django Chroniclesbackdochttp://www.blogger.com/profile/12166034019168376872noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-101972930701754350.post-42173662124638330342013-10-13T08:02:00.002-07:002013-10-13T08:02:38.662-07:00Republican Poll Numbers RealityIt'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.backdochttp://www.blogger.com/profile/12166034019168376872noreply@blogger.com0tag:blogger.com,1999:blog-101972930701754350.post-44126028142715454662009-01-02T06:25:00.000-08:002009-01-08T21:13:17.658-08:00Configuring Mulitple Django Apps under one Project<span style="font-weight: bold; text-decoration: underline;">Setting the Stage:</span><br /><br />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.<br /><br />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).<br /><!--<br /><span style="font-weight: bold; text-decoration: underline;">Point of View:</span><br /><br />As probably many of you, I have set up serveral of my own php sites. Consequently, I believe it will be easiest to begin with a review of that configuration, then see how it relates to a Django set up. I'm familiar enough with Apache to get Apache working in conjuction with my physical directory structure. Basically, I try to think about it like this:<br /><br />Basic Configuration in a LAMP Set Up:<br /><span style="margin-left: 15px;">DocumentRoot = "/usr/local/www/doc_root"</span><br />Physical Location of "doc_root" files:<br /><span style="margin-left: 15px;">/usr/local/www/doc_root/index.php</span><br />To see the index.php file in a browser, you would navigate to:<br /><span style="margin-left: 15px;">http://www.mydomain.com/index.php</span><br /><br />A couple of things to note here. First, if you have the default Apache configuration, you don't actually have to type "index.php". It is assumed. Second, the DocumentRoot directive and the domain name are basically equivalent. For example, "http://www.mydomain.com/" takes you to "/usr/local/www/doc_root". Therefore, it is easy to see that if you wanted to add files or directories to your physical directory structure, you would append that to your URL in your browser. Enough about php/Apache. On to Django.<br />--><br /><span style="font-weight: bold; text-decoration: underline;">Getting Started with the Pieces and the Problems:</span><br /><br />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. <br /><br /><span style="font-weight:bold; text-decoration: underline;">Identifying the pieces:</span><br /><ol><li>settings.py</li><li>urls.py</li><li>Apache config</li><li>physical directory layout</li><li>references to templates, within other templates and views<br /></li></ol>One thing to keep in mind is that when you combine the pieces, they should combine to reveal a full path. Another thing to note is with a PHP set up, the URL you type is can be directly matched to the DocumentRoot and physical file structure. In the case of Django, the URL will be mapped to views, which do not have a physical filesystem structure that matches.<br /><br />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.<br /><br /><span style="font-weight: bold; text-decoration: underline;">Assuming You have the Django Polls Tutorial Up and Running:</span><br /><br />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:<br /><br /><div id="showtree" style="text-align: center; border: 1px solid black; background-color: silver;height: 20px; width: 250px;" onclick="document.getElementById('tree').setAttribute('style', 'display: inline');document.getElementById('showtree').style.display = 'none';document.getElementById('hidetree').style.display = 'inline';"><span style="line-height: 20px; padding: 5px 15px">Show File Tree (+)</span><br /></div><div id="hidetree" style="text-align: center; display: none; border: 1px solid black; background-color: silver;height: 20px;width: 250px;" onclick="document.getElementById('tree').setAttribute('style', 'display: none'); document.getElementById('showtree').style.display = 'inline'; document.getElementById('hidetree').style.display = 'none';"><span style="line-height: 20px; padding: 5px 15px">Hide File Tree (-)</span></div><br /><div id="tree" style="display: none"><br /><span style="margin-left: 30px;">/usr/local/www/django/prj_1/</span><br /><span style="margin-left: 60px;">settings.py</span><br /><span style="margin-left: 60px;">urls.py</span><br /><span style="margin-left: 60px;">/admin (the built in Django admin application)</span><br /><span style="margin-left: 90px;">admin.py</span><br /><span style="margin-left: 90px;">views.py</span><br /><span style="margin-left: 90px;">urls.py</span><br /><span style="margin-left: 60px;">/app1</span><br /><span style="margin-left: 90px;">admin.py</span><br /><span style="margin-left: 90px;">views.py</span><br /><span style="margin-left: 90px;">urls.py</span><br /><span style="margin-left: 60px;">/app2</span><br /><span style="margin-left: 90px;">admin.py</span><br /><span style="margin-left: 90px;">views.py</span><br /><span style="margin-left: 90px;">urls.py</span><br /><span style="margin-left: 60px;">/static</span><br /><span style="margin-left: 90px;">/admin</span><br /><span style="margin-left: 120px;">/media</span><br /><span style="margin-left: 150px;">/css</span><br /><span style="margin-left: 150px; white-space: nowrap;">too many files to list here, they were copied from Django's builtin files</span><br /><span style="margin-left: 90px;">/common</span><br /><span style="margin-left: 120px;">/css</span><br /><span style="margin-left: 150px;">base.css</span><br /><span style="margin-left: 60px;">/templates</span><br /><span style="margin-left: 90px;">/admin</span><br /><span style="margin-left: 120px;">base_site.html</span><br /><span style="margin-left: 120px;">index.html</span><br /><span style="margin-left: 90px;">/common</span><br /><span style="margin-left: 120px;">app2_base.html</span><br /><span style="margin-left: 90px;">/app1</span><br /><span style="margin-left: 120px;">detail.html</span><br /><span style="margin-left: 120px;">index.html</span><br /><span style="margin-left: 120px;">results.html</span><br /><span style="margin-left: 120px;">vote.html</span><br /><span style="margin-left: 90px;">/app2</span><br /><span style="margin-left: 120px;">index.html</span><br /></div>I use virtual directories with Apache. I'm not going to going too far into basic Apache configuration, though. Here's the configuration.<br /><br /><div id="showapache" style="text-align: center; border: 1px solid black; background-color: silver;height: 20px; width: 250px;" onclick="document.getElementById('apache').setAttribute('style', 'display: inline');document.getElementById('showapache').style.display = 'none';document.getElementById('hideapache').style.display = 'inline';"><span style="line-height: 20px; padding: 5px 15px">Show Apache Config (+)</span></div><div id="hideapache" style="text-align: center; display: none; border: 1px solid black; background-color: silver;height: 20px;width: 250px;" onclick=" document.getElementById('apache').setAttribute('style', 'display: none'); document.getElementById('showapache').style.display = 'inline'; document.getElementById('hideapache').style.display = 'none';"><span style="line-height: 20px; padding: 5px 15px">Hide Apache Config (-)</span></div><br /><div id="apache" style="display: none"><br /><VirtualHost *:80><br /><div style="margin-left: 75px;"><br /> ServerAdmin webmaster@localhost<br /> DocumentRoot /usr/local/www/django/prj_1/static<br /> ServerName mydomain.com<br /> ServerAlias mydomain.com *.mydomain.com usmstudent<br /> <Directory /><div style="margin-left: 75px;">Options FollowSymLinks<br /> AllowOverride All</div></Directory><br /> <Location "/"><div style="margin-left: 75px;">SetHandler python-program<br /> PythonHandler django.core.handlers.modpython<br /> PythonDebug On<br /> <span style="white-space: nowrap">PythonPath "['/usr/local/www/django/', '/usr/local/www/django/prj_1/'] + sys.path"</span><br /> SetEnv DJANGO_SETTINGS_MODULE prj_1.settings</div></Location><br /><br /> <LocationMatch "\.(css|jpg|js)$"><br /><div style="margin: 0pt 0pt 0pt 75px;">SetHandler None</div></LocationMatch><br /></div><br /></Virtualhost><br /></div><br />The relevant parts of the settings.py.<br /><br /><div id="showsettings" style="text-align: center; border: 1px solid black; background-color: silver;height: 20px; width: 250px;" onclick="document.getElementById('settings').setAttribute('style', 'display: inline');document.getElementById('showsettings').style.display = 'none';document.getElementById('hidesettings').style.display = 'inline';"><span style="line-height: 20px; padding: 5px 15px">Show Settings.py (+)</span></div><div id="hidesettings" style="text-align: center; display: none; border: 1px solid black; background-color: silver;height: 20px;width: 250px;" onclick=" document.getElementById('settings').setAttribute('style', 'display: none'); document.getElementById('showsettings').style.display = 'inline'; document.getElementById('hidesettings').style.display = 'none';"><span style="line-height: 20px; padding: 5px 15px">Hide Settings.py (-)</span></div><br /><div id="settings" style="display: none"><br /><div style="margin-left: 75px;">ADMIN_MEDIA_PREFIX = '/admin/media/'</div><br /><div style="margin-left: 75px;">TEMPLATE_DIRS = (<br /><div style="margin-left: 75px;">'/usr/local/www/django/prj_1/templates',<br /></div>)</div><br /><div style="margin-left: 75px;">INSTALLED_APPS = (<br /><div style="margin-left: 75px;">'django.contrib.auth',<br /> 'django.contrib.contenttypes',<br /> 'django.contrib.sessions',<br /> 'django.contrib.sites',<br /> 'prj_1.app1',<br /> 'prj_1.app2',<br /> 'django.contrib.admin'</div>)</div><br /></div><span style="font-weight: bold;"><br />The urls.py:</span><br /><div style="margin-left: 75px;"><br />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.</div><br /><span style="font-weight: bold;">Referencing templates in code:<br /><br /></span><div style="margin-left: 75px;">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.<br /><br />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:<br /><br /><div style="">{% extends "common/base.html" %}</div><br />We're ready now, to put some of this together. But, I'll do it all at once in the next section.</div><br /><br /><span style="font-weight: bold;">Putting it All Together:</span><br /><br />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.<br /><ol><li>the settings.py and urls.py</li><li>the static pages</li><li>the views</li><li>the templates</li><li>the apps</li></ol><span style="font-weight: bold;">settings.py and urls.py</span><br /><br />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.<br /><br /><span style="font-weight: bold;">static pages</span><br /><br />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:<br /><br /><link rel="stylesheet" href="/common/css/base.css" type="text/css" /><br /><br />So, if you append that to the DocumentRoot, you can find that in my file system.<br /><br />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.<br /><br /><span style="font-weight: bold;">views<br /></span><br />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.<br /><br /><span style="font-weight: bold;">templates</span><br /><br />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.<br /><br /><span style="font-weight: bold;">apps</span><br /><br /><span style="font-weight: bold;"></span>Apps are pretty straight forward, they are resolved by the settings.py. You probably new that from going through the tutorial.backdochttp://www.blogger.com/profile/12166034019168376872noreply@blogger.com0