$ mkdir -p /srv/projects/educator_news $ cd /srv/projects/educator_news $ virtualenv venv $ source venv/bin/activate (venv)$ pip install Django psycopg2 South dj-database-url (venv)$ django-admin.py startproject educator_news (venv)$ cd educator_news (venv)educator_news$ python manage.py runserver ... Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. (venv)educator_news$ cd .. (venv)$ touch .gitignore (venv)$ git add . (venv)$ git commit -am "Initial commit." $ # Create a user for this project. $ sudo -u postgres createuser -P django_user_ednews Enter password for new role: Enter it again: Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) y Shall the new role be allowed to create more new roles? (y/n) n $ su postgres Password: $ psql template1 psql (9.1.10) Type "help" for help. template1=# CREATE DATABASE ednews_db OWNER django_user_ednews ENCODING 'UTF8'; CREATE DATABASE template1=# \q $ su ehmatthes Password: $ $ sudo cp /etc/postgresql/9.1/main/pg_hba.conf /etc/postgresql/9.1/main/pg_hba.conf.original $ sudo nano /etc/postgresql/9.1/main/pg_hba.conf # Add the following line, after a similar line. # Don't delete any lines from pg_hba.conf local ednews_db django_user_ednews md5 $ sudo /etc/init.d/postgresql restart import dj_database_url DATABASES = {'default': dj_database_url.config() } DATABASE_URL=postgres://django_user_mysite:password@localhost/mysite_db # Use my env variables export $(cat /srv/projects/mysite/.env) # .gitignore venv/* *.pyc notes/* .env (venv)educator_news$ python manage.py syncdb INSTALLED_APPS = ( 'django.contrib.auth', ... # Utilities/ libraries 'south', ) (venv)educator_news$ python manage.py syncdb (venv)educator_news$ python manage.py startapp ed_news ###highlight=[8,9] from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # My urls url(r'^', include('ed_news.urls', namespace='ed_news')), url(r'^admin/', include(admin.site.urls)), ) from django.conf.urls import patterns, url from ed_news import views urlpatterns = patterns('', # My urls # --- Educator News home page --- url(r'^$', views.index, name='index'), ) from django.shortcuts import render_to_response from django.template import RequestContext def index(request): # Static index page for now. return render_to_response('ed_news/index.html', {}, context_instance = RequestContext(request)) (venv)educator_news$ mkdir -p educator_news/static/templates/ed_news (venv)educator_news$ touch educator_news/static/templates/ed_news/index.html Educator News ###highlight=[10,11,12,13] # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] ... DIRNAME = os.path.dirname(__file__) TEMPLATE_DIRS = ( os.path.join(DIRNAME, 'static/templates'), ) # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', ... (venv)educator_news$ touch educator_news/educator_news/static/templates/base.html Educator News {% extends base.html %}
This example is a quick exercise to illustrate how the default, static and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.
To see the difference between static and fixed top navbars, just scroll.
Your username and password didn't match. Please try again.
{% endif %} {% endblock %} ###highlight=[4,5,14,15,16,17,18] from django.shortcuts import render_to_response, redirect from django.template import RequestContext from django.contrib.auth import logout from django.core.urlresolvers import reverse def index(request): # Static index page for now. return render_to_response('ed_news/index.html', {}, context_instance = RequestContext(request)) # Authentication views def logout_view(request): logout(request) # Redirect to home page. return redirect('/') ###highlight=[14,21,22,23,24,25,26]