--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMgbqCe3UzvrWFg4fiRSPXp6HtLJoPJmGs8oPSZjAd%3Dxx4ygNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
urlpatterns = [
path('', views.index, name='index'),
path('cookbooks/', views.CookBookListView.as_view(), name='cookbooks'),
path('cookbook/<uuid:pk>', views.CookBookDetailView.as_view(), name='cookbook'),
path('recipe/', views.RecipeListView.as_view(), name='recipes'),
path('recipe/<uuid:pk>', views.RecipeDetailView.as_view(), name='recipe'),
path('family/', views.FamilyDetailView.as_view(), name='family'),
path('recipe/add/', views.RecipeAdd, name='addrecipe'),
#Add Django site authentication urls (for login, logout, password management)
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
class Recipe(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text='Unique ID for this particular recipe across whole library')
cookbook = models.ForeignKey(CookBook,on_delete=models.SET_NULL, null=True, related_name='recipies')
title = models.TextField(max_length=1000, help_text='Enter a brief description of the Recipe')
author = models.TextField(max_length=1000, help_text='Enter the creator of the Recipie', blank=True)
text = models.TextField(max_length=10000, help_text='Enter the recipe')
notes = models.TextField(max_length=10000, help_text='Enter notes on the recipe',blank=True)
pic = models.ImageField(upload_to='media/',blank=True, null=True)
views.py
def RecipeAdd(request):
template_name = 'recipe_add.html'
r = Recipe(cookbook=Family.objects.get(members=request.user).FamilyCookbook)
# If this is a POST request then process the Form data
if request.method == 'POST':
# Create a form instance and populate it with data from the request (binding):
add_recipe_form = AddRecipeForm(request.POST, request.FILES)
# Check if the form is valid:
if add_recipe_form.is_valid():
# process the data in form.cleaned_data as required (here we just write it to the model due_back field)
# book_instance.due_back = book_renewal_form.cleaned_data['renewal_date']
r.author = add_recipe_form.cleaned_data['author']
r.notes = add_recipe_form.cleaned_data['notes']
r.text = add_recipe_form.cleaned_data['text']
r.title = add_recipe_form.cleaned_data['title']
# r.pic=add_recipe_form.cleaned_data['pic'] # file not being returned here
# r.pic = add_recipe_form.data['pic'] # file not being returned here
r.pic = request.FILES['pic'] #file not here
add_recipe_form.save() # save the recipe
# redirect to a new URL:
return HttpResponseRedirect(reverse('recipes'))
# If this is a GET (or any other method) create the default form.
else:
# proposed_renewal_date = datetime.date.today() + datetime.timedelta(weeks=3)
add_recipe_form = AddRecipeForm()
context = {
'form': add_recipe_form,
}
return render(request, 'recipe_add.html', context)
forms.py
class AddRecipeForm( ModelForm ):
pic = ImageField(widget= FileInput) # was widget=PictureWidget
class Meta:
model = Recipe
fields = ('title', 'author', 'text', 'notes', 'pic')
widgets = {
'title': Textarea( attrs={'cols': 40, 'rows': 1} ),
'author': Textarea( attrs={'cols': 40, 'rows': 1} ),
'text': Textarea( attrs={'cols': 40, 'rows': 1} ),
'notes': Textarea( attrs={'cols': 40, 'rows': 1} ),
# 'pic': Textarea(attrs={'cols': 40, 'rows': 1}),
recipe_list.html
<h1>Recipe List</h1>
{% if recipe_list %}
<ul>
{% for recipe in recipe_list %}
<li>
<!-- <a href="{{ recipe.get_absolute_url }}">{{ recipe.title }}</a> {{recipe.author}} -->
<p>{{ recipe.title }}</p> {{recipe.author}}
<p> {{recipe.text}} <p>
<p>{{ recipe.notes }}</p>
{% load static %}
<div class="recipe_image">
{% if recipe.pic %}
<a href="{{ recipe.pic.url }}">{{ recipe.title }}</a>
<img src="{{ recipe.pic.url}}" alt="{{ recipe.title }}" />
{% endif %}
</div>
<p> {{ recipe.pic }}</p>
</li>
{% endfor %}
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA%3Diw_-Siy3yQgn8O9Kj0NC6URxwhebR%3DqO7BvUwzyL9mi9NdQ%40mail.gmail.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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca83632a-89d5-4186-873e-8ef6bf552cc5%40googlegroups.com.
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/oldgrub/media/56288852088__208FCEF9-5890-4633-8BF6-C5C9A82D87EE.JPG |
Using the URLconf defined in familyrecipies.urls
, Django tried these URL patterns, in this order:
The current path, oldgrub/media/56288852088__208FCEF9-5890-4633-8BF6-C5C9A82D87EE.JPG
, didn't match any of these.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d4970488-eae4-4298-96ad-617fac29ae08%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a3dd9edd-c446-4855-895f-6753de7b0a84%40googlegroups.com.
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/oldgrub/media/56288593216__746F513A-D6F6-446D-949F-D0C09E7C4419_sU3W0z5.JPG |
Using the URLconf defined in familyrecipies.urls
, Django tried these URL patterns, in this order:
The current path, oldgrub/media/56288593216__746F513A-D6F6-446D-949F-D0C09E7C4419_sU3W0z5.JPG
, didn't match any of these.
--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/070f631f-d327-47c7-b283-b3bec62b44a6%40googlegroups.com.
(?P<path>.*)in your url is probably the reason why. remove that bit
--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/92369a7c-6d1b-4b6a-a38d-38151bb10772%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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5c9ebd72-bb98-49b8-81eb-dd9da3e7796e%40googlegroups.com.
request.FILES
will only contain data if the request method was POST
and the <form>
that posted the request has the attribute enctype="multipart/form-data"
. Otherwise, request.FILES
will be empty.Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/media/documents/reciper_rK1KS3j.jpg |
Using the URLconf defined in familyrecipies.urls
, Django tried these URL patterns, in this order:
The current path, media/documents/reciper_rK1KS3j.jpg
, didn't match any of these.
You're seeing this error because you have DEBUG = True
in your Django settings file. Change that to False
, and Django will display a standard 404 page.
--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7a1672c8-0f53-41f3-88c0-e3d7a70e7ae3%40googlegroups.com.
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
from django.conf.urls.static import static
from django.conf import settings
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATICFILES_DIRS)
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMgbqCdBfiKTUS38XtwsmZ1ETp6cJ04G8CyiFPne6rOfbc2oog%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJjGCEN-NwJJksZqKK1xw5ozO%2BAUah6MophQrcZjN-ex6nBKQQ%40mail.gmail.com.