Skip to content

Instantly share code, notes, and snippets.

@rpietro
Created January 30, 2014 05:34
Show Gist options
  • Save rpietro/8703109 to your computer and use it in GitHub Desktop.
Save rpietro/8703109 to your computer and use it in GitHub Desktop.
# setting a virtual environment and getting django to run
virtualenv --no-site-packages django_hack
source django_hack/bin/activate
cd django_hack
easy_install django
ls bin
django-admin.py
django-admin.py startproject django_test
cd django_test
python manage.py runserver
# python manage.py runserver 8080 # change server's port
# python manage.py runserver 0.0.0.0:8000 # change server's ip along with the port
deactivate
---
cd django_test
ls
subl settings.py &
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': '/Users/rpietro/django_hack/django_test/django_test/storage.db',
# 'USER': '',
# 'PASSWORD': '',
# 'HOST': '',
# 'PORT': '',
# }
# }
cd ..
python manage.py startapp article
ls
cd article
ls -l
subl models.py&
# class Article(models.Model):
# title = models.CharField(max_length=200)
# body = models.TextField()
# pub_date = models.DateTimeField('date published')
# likes = models.IntegerField()
python manage.py syncdb
# pwd 123
subl settings.py
# INSTALLED_APPS = (
# 'django.contrib.admin',
# 'django.contrib.auth',
# 'django.contrib.contenttypes',
# 'django.contrib.sessions',
# 'django.contrib.messages',
# 'django.contrib.staticfiles',
# 'article',
# )
python manage.py syncdb
# python manage.py sql article
# python manage.py sql reset article # will also kill the data
python manage.py shell
from article.models import Article
from django.utils import timezone
Article.objects.all()
a = Article(title = "test 1", body = "blah", pub_date = timezone.now(), likes = 0)
a
a.save()
a.id
a = Article(title = "test 2", body = "blah", pub_date = timezone.now(), likes = 0)
a.save()
a.id
a = Article(title = "test 3", body = "blah", pub_date = timezone.now(), likes = 0)
a.save()
a.id
Article.objects.all()
subl models.py&
# def __unicode__(self):
# return self.title
python manage.py shell
from article.models import Article
Article.objects.all()
subl views.py
# from django.http import HttpResponse
# # Create your views here.
# def hello(request):
# name = 'Ricardo'
# html = '<html><body> Hi %s. this seems to have worked </body> </html>' % name
# return HttpResponse(html)
subl urls.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment