1
If i understand you right, you want to create view, that render beach separately
You can do something like this, your view:
def get_beach(request, id)
beach = Beach.objects.get(id=id)
return render(request, 'path/to/your/template', {'beach':beach})
urls:
url(r'^someurl/report/(?P<id>[0-9]+)$', views.get_beach(), name='get_beach'),
template url to this page:
<a href= "someurl/report/{{beach.id}}">beach</a>
Edited
Its your view, as i understand, this is detail view, but select all objects(Break.objects.all()
)
def detail(request, break_id):
try:
allBreaks = Break.objects.all()
except Break.DoesNotExist:
raise Http404("404")
return render(request, 'report/index.html', {'allBreaks': allBreaks})
so you have to change this on this:
def detail(request, break_id):
try:
break_detail = Break.objects.get(id=break_id)
return render(request, 'path/to/your/template', {'break_detail':break_detail})
except Break.DoesNotExist:
raise Http404("404")
then your url should look like this:
url(r'^someurl/report/(?P<break_id>[0-9]+)$', views.detail(), name='detail'),
or you can use get_object_or_404
:
def detail(request, break_id):
break_detail = get_object_or_404(Break, id=break_id)
return render(request, ‘path/to/your/template’, {‘break_detail’:break_detail})
Url is the same.
So if you want to access to wind field, you just write this tempalte tag {{break_detail.wind}}
UPD2
change place from this
^admin/
^report/ ^$ [name='index']
^report/ (?P<beach_id>[0-9]+)$ [name='get_report']
to this:
^admin/
^report/(?P<beach_id>[0-9]+)$ [name='get_report']
^report/^$ [name='index']
and delete spaces in urls after report/
- Django crashes on the second form POST while creating a matplotlib.pyplot image from a pandas object
Source:stackexchange.com