To contribute to my own answer, but not to answer the question:
I forgot that Django can automatically render HTML forms using the tagging 
language.

>From the Django Docs https://docs.djangoproject.com/en/4.1/topics/forms/()
*The template¶ 
<https://docs.djangoproject.com/en/4.1/topics/forms/#the-template>* 

*We don’t need to do much in our name.html template:*
*<form action="/your-name/" method="post"> {% csrf_token %} {{ form }} 
<input type="submit" value="Submit"> </form> *

*All the form’s fields and their attributes will be unpacked into HTML 
markup from that {{ form }} by Django’s template language.*
I will use this to update my template context. But I don't think this is 
the cause of the url routing error.
Michael
On Saturday, April 29, 2023 at 6:27:33 PM UTC-7 Michael Starr wrote:

> This isn't the exact name of the error; I'm sure you all have encountered 
> the bad URL error before. But, it tells me it can't find the pet matching 
> the query (I'm making a pet website), and it checked the urls in the order 
> listed below. I mean, you know, in the order in the urls.py file.
>
> Another url works from the project urls.py file, but this url is in the 
> app urls.py file. But it does check the imported urls.
>
> This url should be routing to a form template which is connected to a form 
> view to update a photo object in my models.
>
> I'm not sure which files would be relevant to share. Here are the ones I'm 
> guessing may help:
>
> project urls.py
> 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')),
> ]
>
> app urls.py
> 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"),
>     path("pet/photoupload/", views.PetPhotoUploadView.as_view(), name = 
> "photo_upload"),
> ]
> url in question is the bottom one (photo_upload)
>
> template (photo_upload.html)
> <!DOCTYPE html>
> <html>
>     <head>
>
>     </head>
>     <body>
>         <label>Upload a photo of your pet: <input type="file" /></label>
>     </body>
> </html>
>
> app views
> from django.shortcuts import render
> from django.views.generic import (ListView,
>                                   DetailView, FormView)
> from pet_profile.models import PetOwner, Pet, PetPhoto, PetStory
> from pet_profile.forms import PhotoUploadForm
>
> class PetOwnerListView(ListView):
>     model = PetOwner
>     context_object_name = "owner_list"
>     template_name = "home.html"
>
>     
> # def all_pet_photos(request):
> #     pets = Pet.objects.all()
> #     pet_data = {}
> #     for pet in pets:
> #         pet_data[pet] = PetPhoto.objects.filter(pets=pet)
> #     context = {'pet_data': pet_data}
> #     return render(request, 'pet_owner_profile.html', context)
>
> class PetOwnerDetailView(DetailView):
>     model = PetOwner
>     context_object_name = "owner"
>     template_name = "pet_owner_profile.html"
>     def get_context_data(self, *args, **kwargs):
>         context = super().get_context_data(**kwargs)
>         pets = Pet.objects.all()
>         pet_data = {}
>         for pet in pets:
>             pet_data[pet] = PetPhoto.objects.filter(pets=pet)
>         context['pet_data'] = pet_data
>         return context
>
> class PetListView(ListView):
>     model = Pet
>     context_object_name = "pet_list"
>
> class PetDetailView(DetailView):
>     model = Pet
>     context_object_name = "pet"
>
> class PetPhotoUploadView(FormView):
>     template_name = "photo_upload.html"
>     form_class = PhotoUploadForm
>
> class PetPhotoListView(ListView):
>     model = PetPhoto
>     context_object_name = "pet_photo_list"
>
> class PetPhotoDetailView(DetailView):
>     model = PetPhoto
>     context_object_name = "pet_photo"
>
> class PetStoryListView(ListView):
>     model = PetStory
>     context_object_name = "pet_story_list"
>
> class PetStoryDetailView(DetailView):
>     model = PetStory
>     context_object_name = "pet_story"
>
> view in question is PetPhotoUploadView
>
> Thanks in advance.
> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6c5ead2a-764e-4fa8-a903-a86ae5def321n%40googlegroups.com.

Reply via email to