Commit 278c0d7c authored by onny's avatar onny
Browse files

Initial commit

parents
Pipeline #37 canceled with stages
db.sqlite3
*.pyc
# Django and Vue.JS
This repository contains a simple example application with a backend in Django and a frontend in Vue.JS.
"""
Django settings for djangovuejs project.
Generated by 'django-admin startproject' using Django 1.9.5.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'l@b$p)ti9(x&&8&=s2h9tv@m^u0tij3l9x%8k(41sa-^q_a)bs'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'joblist',
]
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'djangovuejs.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates/')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'djangovuejs.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
if DEBUG:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
else:
STATIC_ROOT=os.path.join(BASE_DIR,'static/')
"""djangovuejs URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework import routers
from joblist.views import job_list, JobsViewSet
# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'jobs', JobsViewSet)
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', job_list),
url(r'^api/', include(router.urls)),
]
from django.template.response import TemplateResponse
from django.http import HttpResponse
def welcome(request):
html = TemplateResponse(request,'base.html',{})
return HttpResponse(html.render())
\ No newline at end of file
"""
WSGI config for djangovuejs project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangovuejs.settings")
application = get_wsgi_application()
from django.contrib import admin
from .models import JobList
admin.site.register(JobList)
# Register your models here.
from __future__ import unicode_literals
from django.apps import AppConfig
class JoblistConfig(AppConfig):
name = 'joblist'
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-05-03 18:37
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='JobList',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('jobtitle', models.CharField(max_length=100)),
('jobdescription', models.TextField(max_length=300)),
('postdate', models.DateField(auto_now_add=True)),
],
),
]
from __future__ import unicode_literals
from django.db import models
# Create your models here.
class JobList(models.Model):
jobtitle = models.CharField(max_length=100)
jobdescription = models.TextField(max_length=300)
postdate = models.DateField(auto_now_add=True)
from .models import JobList
from rest_framework import serializers
class JobsSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = JobList
fields = ('id', 'jobtitle', 'jobdescription', 'postdate')
from django.test import TestCase
# Create your tests here.
from django.template.response import TemplateResponse
from django.http import HttpResponse
from .models import JobList
from rest_framework import viewsets
from .serializers import JobsSerializer
# Create your views here.
def job_list(request):
context = {}
context['jobs'] = JobList.objects.all()
html = TemplateResponse(request, 'joblist.html', context)
return HttpResponse(html.render())
class JobsViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows jobs to be viewed or edited.
"""
queryset = JobList.objects.all()
serializer_class = JobsSerializer
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangovuejs.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment