settings.py
"""
Django settings for pet_memorial project.

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

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

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '1eovl-=7pwb6e1*c7y@6@s7n0+ig)mxos2im3b_+^%3+rdze&k'

# 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',
    'pet_profile'
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, STATIC_URL)
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join(BASE_DIR, MEDIA_URL)


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 = 'pet_memorial.urls'


TEMPLATE_PROJECT_DIR = os.path.join(BASE_DIR,
'pet_memorial/templates/pet_memorial/')
TEMPLATE_APP_DIR = os.path.join(BASE_DIR,
'pet_profile/templates/pet_profile/')
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_PROJECT_DIR, TEMPLATE_APP_DIR],
        '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 = 'pet_memorial.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/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.2/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.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True





urls.py (in project folder)
from django.contrib import admin
from django.urls import path, include
from . import views
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
    path('admin/', admin.site.urls),
    path('home/', views.HomeView.as_view(), name='home_view'),
    path('', include('pet_profile.urls')),
]

urls.py (in app folder)
from django.contrib import admin
from django.urls import path
from pet_profile import views

urlpatterns = [
    path("pet/<slug:slug>/", views.PetDetailView.as_view(), name = 
"pet_profile"),
    path("owner/<slug:slug>/", views.PetOwnerDetailView.as_view(), name = 
"owner_profile"),
]

On Wednesday, April 12, 2023 at 12:21:28 AM UTC-7 Chelsea Fan wrote:

can see your settings.py and urls.py inside project folder? 

On Wed, Apr 12, 2023 at 11:57 AM David Nugent <dav...@uniquode.io> wrote:

It is very important to understand the difference between “static” and 
“media”. The two are somewhat similar, and the code to handle (serve) each 
is even almost identical. Conceptually though they are quite different 
things.

static files are assets provided by your app and served to satisfy the 
direct needs of your app - e.g. javascript, css and other assets which 
never change, updated or rendered.
media files are more fluid things, usually uploaded or processed files, 
objects delivered by the application that are not a core part of rendering 
web pages.

Both STATIC_URL and MEDIA_URL are set up in your settings. In production, 
either or both may be served externally to django.

By default, MEDIA serving is not configured in Django settings, but there 
are many mentions of static files with a dozen or so possible configuration 
items. These are there because such configuration is important right at the 
start of developing a Django app.

If you need information on media handling though, you need to go back to 
the Django docs as there are no hints on how to do this in the default 
generated configuration.

The point is - do not confuse the two, and definitely do not try to tangle 
both as it will eventually lead to problems. Configure media separately 
from static and you will not encounter any of those problems, especially so 
when you get to deploying to production where you may wish to handle them 
differently (serving from cloud vs locally and choice of what served each 
etc and a myriad of other choices).

So, back to your problem, I would guess that you are simply missing a url 
handler for your media files at path(‘media/‘,…(, and the path stored in 
your db is almost definitely correct. The handler you will probably use in 
development mode will look something like your dev static files config, 
except for MEDIA_URL and pointing to the file system location where they 
are actually being uploaded.

HTH,
David



From: Michael Starr <starr...@gmail.com>
Reply: django...@googlegroups.com <django...@googlegroups.com>
Date: 12 April 2023 at 18:00:56
To: Django users <django...@googlegroups.com>
Subject:  Image uploaded to database but not displaying 

I am finding that the url of files stored in a database with Django is 
automated to /media/[filename], which is neat, because that keeps it 
organized and from images being everywhere. However, only the alt text of 
my file shows--the url is correct but the image doesn't show. I've tried 
using static, as well as just {{ image.url }} and neither method worked for 
me. Also, which method is correct? Can we frikkin decide already? :P

Thank you.
Michael
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an 
email to django-users...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4d1c1c52-c4d8-4f46-8333-adc673095fc1n%40googlegroups.com
 
<https://groups.google.com/d/msgid/django-users/4d1c1c52-c4d8-4f46-8333-adc673095fc1n%40googlegroups.com?utm_medium=email&utm_source=footer>
.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an 
email to django-users...@googlegroups.com.

To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE5VhgU%2BCLvoawzUZrb22PBTDi3-%2ByQDCUzHWesOQRawFky5Nw%40mail.gmail.com
 
<https://groups.google.com/d/msgid/django-users/CAE5VhgU%2BCLvoawzUZrb22PBTDi3-%2ByQDCUzHWesOQRawFky5Nw%40mail.gmail.com?utm_medium=email&utm_source=footer>
.

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fa7db884-5031-4b51-bb17-a2b7dafa8336n%40googlegroups.com.

Reply via email to