Spaces:
Runtime error
Runtime error
gamingflexer
commited on
Commit
·
179f729
1
Parent(s):
8f35ce4
django app added
Browse files- src/app/api/__init__.py +0 -0
- src/app/api/admin.py +3 -0
- src/app/api/apps.py +6 -0
- src/app/api/models.py +3 -0
- src/app/api/templates/catalouge.html +93 -0
- src/app/api/templates/product_single.html +0 -0
- src/app/api/tests.py +3 -0
- src/app/api/urls.py +7 -0
- src/app/api/views.py +10 -0
- src/app/main/__init__.py +0 -0
- src/app/main/asgi.py +16 -0
- src/app/main/settings.py +126 -0
- src/app/main/urls.py +8 -0
- src/app/main/wsgi.py +16 -0
- src/app/manage.py +22 -0
src/app/api/__init__.py
ADDED
|
File without changes
|
src/app/api/admin.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
|
| 3 |
+
# Register your models here.
|
src/app/api/apps.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.apps import AppConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class ApiConfig(AppConfig):
|
| 5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
| 6 |
+
name = 'api'
|
src/app/api/models.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
|
| 3 |
+
# Create your models here.
|
src/app/api/templates/catalouge.html
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Catalogue Page</title>
|
| 7 |
+
<!-- Include Bootstrap CSS -->
|
| 8 |
+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
.catalogue-container {
|
| 11 |
+
padding: 20px;
|
| 12 |
+
}
|
| 13 |
+
.search-bar-container {
|
| 14 |
+
display: flex;
|
| 15 |
+
justify-content: space-between;
|
| 16 |
+
align-items: center;
|
| 17 |
+
margin-bottom: 20px;
|
| 18 |
+
}
|
| 19 |
+
.card {
|
| 20 |
+
margin-bottom: 20px;
|
| 21 |
+
}
|
| 22 |
+
</style>
|
| 23 |
+
</head>
|
| 24 |
+
<body>
|
| 25 |
+
|
| 26 |
+
<div class="container catalogue-container">
|
| 27 |
+
<div class="search-bar-container">
|
| 28 |
+
<form class="form-inline my-2 my-lg-0">
|
| 29 |
+
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
|
| 30 |
+
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
|
| 31 |
+
</form>
|
| 32 |
+
<span id="product-count">Number of Products: 0</span>
|
| 33 |
+
</div>
|
| 34 |
+
<div class="row" id="product-row">
|
| 35 |
+
<!-- Product cards will be inserted here -->
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
<!-- Include Bootstrap JS and its dependencies -->
|
| 40 |
+
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
| 41 |
+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.9.3/dist/umd/popper.min.js"></script>
|
| 42 |
+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
| 43 |
+
|
| 44 |
+
<script>
|
| 45 |
+
// Array of products (replace with your own data)
|
| 46 |
+
var products = [
|
| 47 |
+
{
|
| 48 |
+
title: "Product Title 1",
|
| 49 |
+
text: "Description for product 1",
|
| 50 |
+
imageUrl: "https://plus.unsplash.com/premium_photo-1684164601738-cf486690c601?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw3fHx8ZW58MHx8fHx8"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
title: "Product Title 2",
|
| 54 |
+
text: "Description for product 2",
|
| 55 |
+
imageUrl: "https://plus.unsplash.com/premium_photo-1684164601738-cf486690c601?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw3fHx8ZW58MHx8fHx8"
|
| 56 |
+
},
|
| 57 |
+
// Add more products as needed
|
| 58 |
+
];
|
| 59 |
+
|
| 60 |
+
function displayProducts(products) {
|
| 61 |
+
var productRow = document.getElementById('product-row');
|
| 62 |
+
var productCount = document.getElementById('product-count');
|
| 63 |
+
|
| 64 |
+
// Clear previous products
|
| 65 |
+
productRow.innerHTML = '';
|
| 66 |
+
|
| 67 |
+
// Add new product cards
|
| 68 |
+
products.forEach(function(product) {
|
| 69 |
+
var colDiv = document.createElement('div');
|
| 70 |
+
colDiv.className = 'col-md-4';
|
| 71 |
+
colDiv.innerHTML = `
|
| 72 |
+
<div class="card">
|
| 73 |
+
<img class="card-img-top" src="${product.imageUrl}" alt="Card image cap">
|
| 74 |
+
<div class="card-body">
|
| 75 |
+
<h5 class="card-title">${product.title}</h5>
|
| 76 |
+
<p class="card-text">${product.text}</p>
|
| 77 |
+
<a href="#" class="btn btn-primary">Go somewhere</a>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
`;
|
| 81 |
+
productRow.appendChild(colDiv);
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
// Update product count
|
| 85 |
+
productCount.textContent = 'Number of Products: ' + products.length;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
// Initialize display with products
|
| 89 |
+
displayProducts(products);
|
| 90 |
+
</script>
|
| 91 |
+
|
| 92 |
+
</body>
|
| 93 |
+
</html>
|
src/app/api/templates/product_single.html
ADDED
|
File without changes
|
src/app/api/tests.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.test import TestCase
|
| 2 |
+
|
| 3 |
+
# Create your tests here.
|
src/app/api/urls.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.urls import path
|
| 2 |
+
from . import views
|
| 3 |
+
|
| 4 |
+
urlpatterns = [
|
| 5 |
+
path('', views.catalouge_page, name='index'),
|
| 6 |
+
path('product', views.single_product, name='index'),
|
| 7 |
+
]
|
src/app/api/views.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpResponse
|
| 2 |
+
from django.template import loader
|
| 3 |
+
|
| 4 |
+
def catalouge_page(request):
|
| 5 |
+
template = loader.get_template('catalouge.html')
|
| 6 |
+
return HttpResponse(template.render())
|
| 7 |
+
|
| 8 |
+
def single_product(request):
|
| 9 |
+
template = loader.get_template('product_single.html')
|
| 10 |
+
return HttpResponse(template.render())
|
src/app/main/__init__.py
ADDED
|
File without changes
|
src/app/main/asgi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ASGI config for main project.
|
| 3 |
+
|
| 4 |
+
It exposes the ASGI callable as a module-level variable named ``application``.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from django.core.asgi import get_asgi_application
|
| 13 |
+
|
| 14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')
|
| 15 |
+
|
| 16 |
+
application = get_asgi_application()
|
src/app/main/settings.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Django settings for main project.
|
| 3 |
+
|
| 4 |
+
Generated by 'django-admin startproject' using Django 5.0.2.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.0/topics/settings/
|
| 8 |
+
|
| 9 |
+
For the full list of settings and their values, see
|
| 10 |
+
https://docs.djangoproject.com/en/5.0/ref/settings/
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
| 16 |
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Quick-start development settings - unsuitable for production
|
| 20 |
+
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
|
| 21 |
+
|
| 22 |
+
# SECURITY WARNING: keep the secret key used in production secret!
|
| 23 |
+
SECRET_KEY = 'django-insecure-vjlx+%ey1pf0cgcnm5v0(fc718c0()r@(jnm(rfdla-1zg(v6_'
|
| 24 |
+
|
| 25 |
+
# SECURITY WARNING: don't run with debug turned on in production!
|
| 26 |
+
DEBUG = True
|
| 27 |
+
|
| 28 |
+
ALLOWED_HOSTS = ['34.122.223.224']
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# Application definition
|
| 32 |
+
|
| 33 |
+
INSTALLED_APPS = [
|
| 34 |
+
'django.contrib.admin',
|
| 35 |
+
'django.contrib.auth',
|
| 36 |
+
'django.contrib.contenttypes',
|
| 37 |
+
'django.contrib.sessions',
|
| 38 |
+
'django.contrib.messages',
|
| 39 |
+
'django.contrib.staticfiles',
|
| 40 |
+
'api',
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
MIDDLEWARE = [
|
| 44 |
+
'django.middleware.security.SecurityMiddleware',
|
| 45 |
+
'django.contrib.sessions.middleware.SessionMiddleware',
|
| 46 |
+
'django.middleware.common.CommonMiddleware',
|
| 47 |
+
'django.middleware.csrf.CsrfViewMiddleware',
|
| 48 |
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
| 49 |
+
'django.contrib.messages.middleware.MessageMiddleware',
|
| 50 |
+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
ROOT_URLCONF = 'main.urls'
|
| 54 |
+
STATIC_ROOT = 'static'
|
| 55 |
+
|
| 56 |
+
TEMPLATES = [
|
| 57 |
+
{
|
| 58 |
+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
| 59 |
+
'DIRS': [],
|
| 60 |
+
'APP_DIRS': True,
|
| 61 |
+
'OPTIONS': {
|
| 62 |
+
'context_processors': [
|
| 63 |
+
'django.template.context_processors.debug',
|
| 64 |
+
'django.template.context_processors.request',
|
| 65 |
+
'django.contrib.auth.context_processors.auth',
|
| 66 |
+
'django.contrib.messages.context_processors.messages',
|
| 67 |
+
],
|
| 68 |
+
},
|
| 69 |
+
},
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
WSGI_APPLICATION = 'main.wsgi.application'
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# Database
|
| 76 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
|
| 77 |
+
|
| 78 |
+
DATABASES = {
|
| 79 |
+
'default': {
|
| 80 |
+
'ENGINE': 'django.db.backends.sqlite3',
|
| 81 |
+
'NAME': BASE_DIR / 'db.sqlite3',
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# Password validation
|
| 87 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
| 88 |
+
|
| 89 |
+
AUTH_PASSWORD_VALIDATORS = [
|
| 90 |
+
{
|
| 91 |
+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
| 101 |
+
},
|
| 102 |
+
]
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# Internationalization
|
| 106 |
+
# https://docs.djangoproject.com/en/5.0/topics/i18n/
|
| 107 |
+
|
| 108 |
+
LANGUAGE_CODE = 'en-us'
|
| 109 |
+
|
| 110 |
+
TIME_ZONE = 'UTC'
|
| 111 |
+
|
| 112 |
+
USE_I18N = True
|
| 113 |
+
|
| 114 |
+
USE_TZ = True
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# Static files (CSS, JavaScript, Images)
|
| 118 |
+
# https://docs.djangoproject.com/en/5.0/howto/static-files/
|
| 119 |
+
|
| 120 |
+
STATIC_URL = 'static/'
|
| 121 |
+
|
| 122 |
+
# Default primary key field type
|
| 123 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
|
| 124 |
+
|
| 125 |
+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
| 126 |
+
|
src/app/main/urls.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
from django.urls import path
|
| 3 |
+
from django.urls import include
|
| 4 |
+
|
| 5 |
+
urlpatterns = [
|
| 6 |
+
path('admin/', admin.site.urls),
|
| 7 |
+
path('', include('api.urls')),
|
| 8 |
+
]
|
src/app/main/wsgi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
WSGI config for main project.
|
| 3 |
+
|
| 4 |
+
It exposes the WSGI callable as a module-level variable named ``application``.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from django.core.wsgi import get_wsgi_application
|
| 13 |
+
|
| 14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')
|
| 15 |
+
|
| 16 |
+
application = get_wsgi_application()
|
src/app/manage.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Django's command-line utility for administrative tasks."""
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def main():
|
| 8 |
+
"""Run administrative tasks."""
|
| 9 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')
|
| 10 |
+
try:
|
| 11 |
+
from django.core.management import execute_from_command_line
|
| 12 |
+
except ImportError as exc:
|
| 13 |
+
raise ImportError(
|
| 14 |
+
"Couldn't import Django. Are you sure it's installed and "
|
| 15 |
+
"available on your PYTHONPATH environment variable? Did you "
|
| 16 |
+
"forget to activate a virtual environment?"
|
| 17 |
+
) from exc
|
| 18 |
+
execute_from_command_line(sys.argv)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == '__main__':
|
| 22 |
+
main()
|