Idea Transcript
CODE, NODE, NOTE CODE, NODE, NOTE CODE, NODE, NOTE
Home Home
About About
Home
About
pip install django
easy_install django
django-admin.py startproject coba
python manage.py startapp hello
coba | manage.py | +---coba | settings.py | urls.py | wsgi.py | __init__.py | \---hello models.py tests.py views.py __init__.py
#tambahkan kedua baris dibawah ini pada bagian paling atas untuk mengetahui lokasi project import os PROJECT_PATH = os.path.realpath(os.path.dirname(__file__)) DEBUG = True ........ TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. )
PROJECT_PATH + '/../templates/',
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', # daftarkan app hello kita 'hello', ) .......
from django.views.generic import TemplateView class HelloView(TemplateView): template_name = "hello/hello.html"
Hello Django!!
from django.conf.urls import patterns, include, url ....... from hello.views import HelloView urlpatterns = patterns('', ....... # request hello diarahkan ke view HelloView (r'^hello/', HelloView.as_view()), )
+---coba | manage.py | +---coba | settings.py | urls.py | wsgi.py | __init__.py | +---hello | models.py | tests.py | views.py | __init__.py | \---templates \---hello
hello.html
>python manage.py runserver Validating models... 0 errors found Django version 1.4.3, using settings 'coba.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.
←
Õ