Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file modified prajesh_gohel/.DS_Store
Binary file not shown.
25 changes: 25 additions & 0 deletions prajesh_gohel/APIs_and_AJAX/Pokemon/bulbasaur.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bulbasaur</title>
</head>
<body>
<div id="bulbasaur"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.get("https://pokeapi.co/api/v2/pokemon/1", function(res){
var html_str = "";
html_str += "<h4>Types</h4>";
html_str += "<ul>";
for(var i = 0; i < res.types.length; i++){
html_str += "<li>" + res.types[i].type.name + "</li>";
}
html_str += "</ul>";
$("#bulbasaur").html(html_str)
}, "json");
});
</script>
</body>
</html>
21 changes: 14 additions & 7 deletions prajesh_gohel/APIs_and_AJAX/Pokemon/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
<html>
<head>
<meta charset="utf-8">
<title>HTTP Request Response</title>
<title>Pokedex</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
</head>
<body>
<div id="images">

<div class="container-fluid">
<div class="row">
<div class="col-6" id="images"></div>
<div class="col-4" id="pokedex"></div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.get("https://pokeapi.co/api/v2/pokemon/1", function(res){
console.log(res);
}, "json");
});
function loop() {
for(i=1; i<=802; i++) {
console.log(i);
var pokemon = "<img src='http://pokeapi.co/media/sprites/pokemon/"+i+".png' alt='Pokemon'>"
console.log(pokemon)
for(i=1; i<=151; i++) {
var pokemon = "<a href='https://pokeapi.co/api/v2/pokemon/"+i+"'><img id="+i+" src='http://pokeapi.co/media/sprites/pokemon/"+i+".png' alt='Pokemon'></a>"
$('#images').append(pokemon)
}
}
Expand Down
Binary file modified prajesh_gohel/Python/.DS_Store
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
121 changes: 121 additions & 0 deletions prajesh_gohel/Python/ajax_django/ajax_example/ajax_example/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""
Django settings for ajax_example project.

Generated by 'django-admin startproject' using Django 2.0.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/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/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'i%tdllmf&%f89bt9rx(@z6s6iu6l4z07sh!&wec*_$h^qm&(^m'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'apps.autosearch',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'ajax_example.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'ajax_example.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/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/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/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/2.0/howto/static-files/

STATIC_URL = '/static/'
20 changes: 20 additions & 0 deletions prajesh_gohel/Python/ajax_django/ajax_example/ajax_example/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""ajax_example URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path, include

urlpatterns = [
path('', include('apps.autosearch.urls')),
]
16 changes: 16 additions & 0 deletions prajesh_gohel/Python/ajax_django/ajax_example/ajax_example/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for ajax_example 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/2.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ajax_example.settings")

application = get_wsgi_application()
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AutosearchConfig(AppConfig):
name = 'autosearch'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.0.7 on 2018-07-24 22:42

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
]
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from __future__ import unicode_literals
from django.db import models

class User(models.Model):
name = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __repr__(self):
return "<User object: {}>".format(self.name)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>Find all users whose name starts with
<form id='myForm' method='POST' action='/users/api'>
{% csrf_token %} <!-- add csrf_token if you're using Django -->
<input type='text' id='starts_with' name='starts_with' value=''>
</form>
</p>
<div id='placeholder'></div>
<script>
$('#starts_with').keyup(function() {
console.log('sending the following information', $('#myForm').serialize());
$.ajax({
method: "POST",
url: "/users/api",
data: $('#myForm').serialize()
})
.done(function( response ) {
console.log('received response:', response);
$('#placeholder').html(response);
});
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('', views.autosearch),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.shortcuts import render, HttpResponse, redirect
from .models import *

def autosearch(request):
context = {
'users': User.objects.filter(name=request.POST['starts_with'])
}
return render(request, 'ajax_example/autosearch.html', context)
Binary file not shown.
15 changes: 15 additions & 0 deletions prajesh_gohel/Python/ajax_django/ajax_example/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ajax_example.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
Binary file added prajesh_gohel/Python/django_ORM/Courses.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions prajesh_gohel/Python/django_ORM/belt_reviewer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
** Conceptual Questions **

1. What is the flow of information in a typical request, from when we type an address on our browser, to when we receive the response on our browser?

Say we are at localhost:8000 and we want to get to localhost:8000/users. The first thing that will happen is the browser will send an HTTP GET request for everything in /users. Then, the server processes all of that information and sends a GET method over to the browser, where it is converted into HTML, CSS, and JavaScript.

2. What is MVC, OOP and procedural programming? Why would we use each?

MVC stands for model-view-controller, and it is a type of framework that separates the information into different parts to ease the process of creating backend.
OOP stands for object-oriented-programming, and it refers to organizing information in "objects" instead of "actions"; it allows us to manipulate the objects themselves when creating backend.

3. What is jQuery and why do we use it?

jQuery is a library that utilizes JavaScript code and simplifies it to lessen the amount of code you would normally need with pure JavaScript.

4. What are some ways to make your website uniform across multiple browsers?

One way to ensure uniformity is to validate your HTML code with w3validator: this site checks not only any errors you have made in your HTML but also warns you about browser compatibility.

5. What are the differences between submitting a form via method="post" vs method="get"?

A get method is a nonsecure method that is used to get to another route. A post method is a more secure route that protects any information coming in (including passwords, email, etc), and spits it back out to a different route that has a get method.

6. What are the advantages/disadvantages of sending data to the server in the url vs making a post request?

The biggest disadvantage of not using a post request is all of the information that was inputted in a form will be displayed in the url itself when the form is submitted. This can be extremely dangerous as hackers can easily take that information and do whatever they want with it.

7. Why should we never render a page on a post request.

The post method handles all of the processing from the submitted form; it will not allow you to actually render anything. If you did make it to where it renders AND handles a post request, a person would be resubmitting that data from the form every-time they refresh the page.

8. You notice that when you click submit on a form, your app breaks. Describe how you would approach debugging this problem.

The first thing to do is to put in a print function in the route that it is going to in order to see if the browser is actually getting to that particular route or function. If not, see what you can do to fix the path. If it does, check any syntax issues, key errors, etc., until your form finally submits properly. Just do double check, see if the information is actually stored in the database.

9. What is an ORM and why do we use it? What are its advantages and also its disadvantages.

ORM stands for object-relational-mapping, and it allows a developer to create and run SQL codes using all of the backend. There is usually a file called "models" that stores the information for the tables and relationships of those tables. The big advantage is it can save time if you know the ORM syntax. The big disadvantage is it can be difficult to actually visualize the tables, so a browser is normally recommended if using ORM.
Empty file.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions prajesh_gohel/Python/django_ORM/blogs/apps/blogs_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BlogsAppConfig(AppConfig):
name = 'blogs_app'
Loading