Re: URL evaluates to 'slug' literally instead of the variable slug

2022-12-20 Thread Michael Starr
No reply yet, so bump.

On Friday, December 16, 2022 at 5:51:14 PM UTC-8 Michael Starr wrote:

> I hope someone is still subscribed to this post. I had another question...
>
> I looked up your link, about context dictionary, presumably to modify the 
> value returned by the function, like you said, to add the pets to it. I 
> don't know what to loop or iterate over to get all the pets, first off. I 
> know how to add them, I think, that would just be context[pet id or 
> something] = . Secondly, I'm assuming this function, 
> get_context_data, goes in the models file. I understand how to retrieve 
> context from the dictionary, you explained that as well as the professor in 
> the course I took on Django, so no problems there (so far).
>
> I think that's it, actually.
>
> Thanks in advance, hugely appreciate any help anyone can offer.
>
> Best,
> Mike
>
> On Thursday, December 15, 2022 at 2:54:59 PM UTC-8 Michael Starr wrote:
>
>> Sorry for that crass, asinine comment. I had a flare up of my condition.
>> Thank you all for the help.
>> Mike
>>
>> On Sunday, December 11, 2022 at 4:32:04 PM UTC-8 Michael Starr wrote:
>>
>>> It's poorly written and mine isn't. Am I better than them.
>>
>>
>>>
>>> On Monday, December 5, 2022 at 6:36:30 AM UTC-8 elvisa...@gmail.com 
>>> wrote:
>>>
 Good !

 Le dim. 4 déc. 2022 à 22:04, Michael Starr  a 
 écrit :

> Thank you, Peter. I forgot to acknowledge your contribution.
>
> On Wednesday, November 30, 2022 at 4:43:47 PM UTC-8 Ryan Nowakowski 
> wrote:
>
>> On Wed, Nov 30, 2022 at 09:16:39AM -0800, Michael Starr wrote: 
>> > Thank you. Though, that hard codes everything, which is bad. How do 
>> I 
>> > generalize it? 
>>
>> You'll need to do 2 things: 
>>
>> 1. Add the pet(s) you want to the template context, probably by 
>> implementing get_context_data[1]. 
>>
>> 2. Change your template to use the pet from the template context 
>> instead of the hard code pet, Mocha. Assuming your pet in the template 
>> context is named 'pet': 
>>
>> Pet Profile: {{ 
>> pet.name }} 
>>
>> ...alternatively since you've implemented get_absolute_url: 
>>
>> Pet Profile: {{ pet.name }} 
>>
>>
>> [1] 
>> https://docs.djangoproject.com/en/4.1/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data
>>  
>>
> -- 
> 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/e8afb697-d067-4cc6-bda8-93dd9b8748een%40googlegroups.com
>  
> 
> .
>


-- 
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/0876cdf6-9e88-4336-9254-52aac5738c34n%40googlegroups.com.


Re: URL evaluates to 'slug' literally instead of the variable slug

2022-12-16 Thread Michael Starr
I hope someone is still subscribed to this post. I had another question...

I looked up your link, about context dictionary, presumably to modify the 
value returned by the function, like you said, to add the pets to it. I 
don't know what to loop or iterate over to get all the pets, first off. I 
know how to add them, I think, that would just be context[pet id or 
something] = . Secondly, I'm assuming this function, 
get_context_data, goes in the models file. I understand how to retrieve 
context from the dictionary, you explained that as well as the professor in 
the course I took on Django, so no problems there (so far).

I think that's it, actually.

Thanks in advance, hugely appreciate any help anyone can offer.

Best,
Mike

On Thursday, December 15, 2022 at 2:54:59 PM UTC-8 Michael Starr wrote:

> Sorry for that crass, asinine comment. I had a flare up of my condition.
> Thank you all for the help.
> Mike
>
> On Sunday, December 11, 2022 at 4:32:04 PM UTC-8 Michael Starr wrote:
>
>> It's poorly written and mine isn't. Am I better than them.
>
>
>>
>> On Monday, December 5, 2022 at 6:36:30 AM UTC-8 elvisa...@gmail.com 
>> wrote:
>>
>>> Good !
>>>
>>> Le dim. 4 déc. 2022 à 22:04, Michael Starr  a 
>>> écrit :
>>>
 Thank you, Peter. I forgot to acknowledge your contribution.

 On Wednesday, November 30, 2022 at 4:43:47 PM UTC-8 Ryan Nowakowski 
 wrote:

> On Wed, Nov 30, 2022 at 09:16:39AM -0800, Michael Starr wrote: 
> > Thank you. Though, that hard codes everything, which is bad. How do 
> I 
> > generalize it? 
>
> You'll need to do 2 things: 
>
> 1. Add the pet(s) you want to the template context, probably by 
> implementing get_context_data[1]. 
>
> 2. Change your template to use the pet from the template context 
> instead of the hard code pet, Mocha. Assuming your pet in the template 
> context is named 'pet': 
>
> Pet Profile: {{ 
> pet.name }} 
>
> ...alternatively since you've implemented get_absolute_url: 
>
> Pet Profile: {{ pet.name }} 
>
>
> [1] 
> https://docs.djangoproject.com/en/4.1/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data
>  
>
 -- 
 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/e8afb697-d067-4cc6-bda8-93dd9b8748een%40googlegroups.com
  
 
 .

>>>

-- 
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/8763db79-da9f-4487-8ad2-90a3595079bdn%40googlegroups.com.


Re: URL evaluates to 'slug' literally instead of the variable slug

2022-12-15 Thread Michael Starr
Sorry for that crass, asinine comment. I had a flare up of my condition.
Thank you all for the help.
Mike

On Sunday, December 11, 2022 at 4:32:04 PM UTC-8 Michael Starr wrote:

> It's poorly written and mine isn't. Am I better than them.
>
> On Monday, December 5, 2022 at 6:36:30 AM UTC-8 elvisa...@gmail.com wrote:
>
>> Good !
>>
>> Le dim. 4 déc. 2022 à 22:04, Michael Starr  a 
>> écrit :
>>
>>> Thank you, Peter. I forgot to acknowledge your contribution.
>>>
>>> On Wednesday, November 30, 2022 at 4:43:47 PM UTC-8 Ryan Nowakowski 
>>> wrote:
>>>
 On Wed, Nov 30, 2022 at 09:16:39AM -0800, Michael Starr wrote: 
 > Thank you. Though, that hard codes everything, which is bad. How do I 
 > generalize it? 

 You'll need to do 2 things: 

 1. Add the pet(s) you want to the template context, probably by 
 implementing get_context_data[1]. 

 2. Change your template to use the pet from the template context 
 instead of the hard code pet, Mocha. Assuming your pet in the template 
 context is named 'pet': 

 Pet Profile: {{ 
 pet.name }} 

 ...alternatively since you've implemented get_absolute_url: 

 Pet Profile: {{ pet.name }} 


 [1] 
 https://docs.djangoproject.com/en/4.1/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data
  

>>> -- 
>>> 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/e8afb697-d067-4cc6-bda8-93dd9b8748een%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
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/43d43c8a-6393-4398-8040-7431a915844bn%40googlegroups.com.


Re: URL evaluates to 'slug' literally instead of the variable slug

2022-12-11 Thread Michael Starr
It's poorly written and mine isn't. Am I better than them.

On Monday, December 5, 2022 at 6:36:30 AM UTC-8 elvisa...@gmail.com wrote:

> Good !
>
> Le dim. 4 déc. 2022 à 22:04, Michael Starr  a 
> écrit :
>
>> Thank you, Peter. I forgot to acknowledge your contribution.
>>
>> On Wednesday, November 30, 2022 at 4:43:47 PM UTC-8 Ryan Nowakowski wrote:
>>
>>> On Wed, Nov 30, 2022 at 09:16:39AM -0800, Michael Starr wrote: 
>>> > Thank you. Though, that hard codes everything, which is bad. How do I 
>>> > generalize it? 
>>>
>>> You'll need to do 2 things: 
>>>
>>> 1. Add the pet(s) you want to the template context, probably by 
>>> implementing get_context_data[1]. 
>>>
>>> 2. Change your template to use the pet from the template context instead 
>>> of the hard code pet, Mocha. Assuming your pet in the template context is 
>>> named 'pet': 
>>>
>>> Pet Profile: {{ pet.name 
>>> }} 
>>>
>>> ...alternatively since you've implemented get_absolute_url: 
>>>
>>> Pet Profile: {{ pet.name }} 
>>>
>>>
>>> [1] 
>>> https://docs.djangoproject.com/en/4.1/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data
>>>  
>>>
>> -- 
>> 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/e8afb697-d067-4cc6-bda8-93dd9b8748een%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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/c209ab85-1e49-47f0-a6a2-570b48f37021n%40googlegroups.com.


Re: URL evaluates to 'slug' literally instead of the variable slug

2022-11-30 Thread Michael Starr
Thank you. Though, that hard codes everything, which is bad. How do I 
generalize it?


Also, this worked. I had to specify template_name = pet_profile.html in 
the pet detail view.



On 11/30/22 7:15 AM, Ryan Nowakowski wrote:

On Tue, Nov 29, 2022 at 06:35:25PM -0800, Michael Starr wrote:

*home folder / home.html*


   
 
 
   
   
 test
 Pet Profile: Mocha
   


In your home.html you've hard coded a link to a specific pet named Mocha.
You'll need to hard code the slug as well so:

Pet Profile: Mocha



--
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/4f4f2184-48c9-5448-2fe2-a1ae5550a89c%40spinningcow.xyz.


Re: URL evaluates to 'slug' literally instead of the variable slug

2022-11-30 Thread peteru mimo
Make your urls patterns at pet app 

path('pet/', pet_views.PetDetailView.as_view(), 
name='pet_details'),] 

On Wednesday, November 30, 2022 at 2:52:36 PM UTC+1 mi...@spinningcow.xyz 
wrote:

> Code is first, query is last (below). Thanks in advance.
>
>
> *home directory urls.py*
> from django.contrib import admin
> from django.urls import path,include
> from . import views
>
> urlpatterns = [
> path("admin/", admin.site.urls, name='admin'),
> path("", views.Home.as_view(), name="home"),
> path("pet/", include('pet.urls')),
> ]
>
>
>
> *home directory views.py*
> from django.shortcuts import render
> from django.views.generic.detail import DetailView
> from django.views.generic.base import TemplateView
> from django.views.generic import View
>
> class Home(TemplateView):
> template_name = 'home.html'
>
>
>
> *app "pet" urls.py*
> from django.contrib import admin
> from django.urls import path
> from . import views as pet_views
> from .models import Pet
>
> urlpatterns = [
> path('', pet_views.PetDetailView.as_view(), 
> name='pet_details'),]
>
>
>
> *app "pet" views.py*
> from django.shortcuts import render
> from django.views.generic.detail import DetailView
> from pet.models import Pet
>
> class PetDetailView(DetailView):
> model = Pet
> slug_url_kwarg = 'slug'
> slug_field = 'slug'
>
>
>
>
> *app "pet" models.py*
> from django.db import models
> from django.utils.text import slugify
>
> class Pet(models.Model):
> name = models.CharField(max_length=255)
> age = models.IntegerField()
> slug = models.SlugField(allow_unicode=True, max_length=100, 
> unique=True, default="default_pet_slug")
>
> def __str__(self):
> return self.name
>
> def save(self, *args, **kwargs):
> self.slug = slugify(self.name)
> super().save(*args, **kwargs)
>
> def get_absolute_url(self):
> return reverse("pet:pet_details", kwargs={"slug": self.slug})
>
>
>
> *apps.py*
> from django.apps import AppConfig
>
> class PetConfig(AppConfig):
> default_auto_field = "django.db.models.BigAutoField"
> name = "pet"
>
>
>
> *admin.py*
> from django.contrib import admin
> from .models import Pet
>
> admin.site.register(Pet)
>
>
>
> *settings.py*
> """
> Django settings for pet_memorial project.
>
> Generated by 'django-admin startproject' using Django 4.1.
>
> For more information on this file, see
> https://docs.djangoproject.com/en/4.1/topics/settings/
>
> For the full list of settings and their values, see
> https://docs.djangoproject.com/en/4.1/ref/settings/
> """
>
> from pathlib import Path
>
> # Build paths inside the project like this: BASE_DIR / 'subdir'.
> BASE_DIR = Path(__file__).resolve().parent.parent
>
>
> # Quick-start development settings - unsuitable for production
> # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
>
> # SECURITY WARNING: keep the secret key used in production secret!
> SECRET_KEY = 
> "django-insecure-zfb*2fvvz=_komv(#8(ho)ckc-+a3$^!@tua2#n^c&0*st=xm6"
>
> # 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",
> ]
>
> 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"
>
> TEMPLATES = [
> {
> "BACKEND": "django.template.backends.django.DjangoTemplates",
> "DIRS": [
> 'pet_memorial/templates/',
> 'pet/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 = "pet_memorial.wsgi.application"
>
>
> # Database
> # https://docs.djangoproject.com/en/4.1/ref/settings/#databases
>
> DATABASES = {
> "default": {
> "ENGINE": "django.db.backends.sqlite3",
> "NAME": BASE_DIR / "db.sqlite3",
> }
> }
>
>
> # Password validation
> # 
> https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
>
> AUTH_PASSWORD_VALIDATORS = [
> {
> "NAME": 
> 

URL evaluates to 'slug' literally instead of the variable slug

2022-11-30 Thread Michael Starr
Code is first, query is last (below). Thanks in advance.


*home directory urls.py*
from django.contrib import admin
from django.urls import path,include
from . import views

urlpatterns = [
path("admin/", admin.site.urls, name='admin'),
path("", views.Home.as_view(), name="home"),
path("pet/", include('pet.urls')),
]



*home directory views.py*
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.base import TemplateView
from django.views.generic import View

class Home(TemplateView):
template_name = 'home.html'



*app "pet" urls.py*
from django.contrib import admin
from django.urls import path
from . import views as pet_views
from .models import Pet

urlpatterns = [
path('', pet_views.PetDetailView.as_view(), 
name='pet_details'),]



*app "pet" views.py*
from django.shortcuts import render
from django.views.generic.detail import DetailView
from pet.models import Pet

class PetDetailView(DetailView):
model = Pet
slug_url_kwarg = 'slug'
slug_field = 'slug'




*app "pet" models.py*
from django.db import models
from django.utils.text import slugify

class Pet(models.Model):
name = models.CharField(max_length=255)
age = models.IntegerField()
slug = models.SlugField(allow_unicode=True, max_length=100, 
unique=True, default="default_pet_slug")

def __str__(self):
return self.name

def save(self, *args, **kwargs):
self.slug = slugify(self.name)
super().save(*args, **kwargs)

def get_absolute_url(self):
return reverse("pet:pet_details", kwargs={"slug": self.slug})



*apps.py*
from django.apps import AppConfig

class PetConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "pet"



*admin.py*
from django.contrib import admin
from .models import Pet

admin.site.register(Pet)



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

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 
"django-insecure-zfb*2fvvz=_komv(#8(ho)ckc-+a3$^!@tua2#n^c&0*st=xm6"

# 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",
]

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"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
'pet_memorial/templates/',
'pet/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 = "pet_memorial.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}


# Password validation
# 
https://docs.djangoproject.com/en/4.1/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/4.1/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
#