Skip to content

Instantly share code, notes, and snippets.

View RedGhoul's full-sized avatar
🌴
On vacation

RedGhoul

🌴
On vacation
View GitHub Profile
from django.shortcuts import render
from django.http import HttpResponse
from first_app.models import Topic,Webpage,AccessRecord
# Create your views here.
def index(request):
webpages_list = AccessRecord.objects.order_by('date')
date_dict = {'access_records': webpages_list}
my_dict = {'insert_me':"This is coming from da Index.html!!!"}
return render(request,'first_app/index.html',context=date_dict)
<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
<meta charset="utf-8">
<title>Django Level Two</title>
<link rel="stylesheet" href="{% static "css/mystyle.css" %}"/>
</head>
<body>
<h1>YOLO LIFE</h1>
from django.db import models
class Topic(models.Model):
top_name = models.CharField(max_length=264,unique=True)
def __str__(self):
return self.top_name
class Webpage(models.Model):
topic = models.ForeignKey(Topic) # notice how easy it is to take care of foreign keys
#For Loops
seq = [1,2,3,4,5,6,3]
for item in seq:
print(item)
dick = {"SAM":1,"FRANK":2,"Dan":3}
for it in dick:
print(it) #outputs the keys
print(dick[it]) #outputs the values
x = 1
y = 1
# basic ifs
if x == y:
print("Hello")
if 2 > 1:
print("Hello as well")
# an else if is a "elif"
if 1 == 1:
#LISTS
# Can have mixed data types
# lists are mutable, they can have any sort of data type, or a mixture of different data types
mylist = [1,2,3]
mylist = ['random',3,4,2,32323,True,23232323,[2,3,2]]
print(mylist) # output "['random', 3, 4, 2, 32323, True, 23232323, [2, 3, 2]]""
print(mylist[1]) # output "3"
print(mylist[:3]) # also supports slicing, also has the same rules as slicing
#output "['random', 3, 4]"
# dynamic typing in action below
#Numbers
a = 5
print(a) # 5
a = 'afasdadfs'
print(a) # afasdadfs
print(2 + 10 * 10 + 3) # python follows bedmass !
var express = require('express')
var app = express()
app.get('/', function (req, res) {
res.send('hello world')
})
import UIKit
//@IBDesignable // allows you to render inside the story board
class GradientView: UIView { // it is inhertating from UIView since that is what we are going to put it in
// these IBInspectablea allow you to assign different colors in the right hand panel
@IBInspectable var topColor: UIColor = UIColor.blue{
didSet{
self.setNeedsLayout()
}