thank you On Thu, May 26, 2016 at 2:00 AM, <python-list-requ...@python.org> wrote:
> Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-requ...@python.org > > You can reach the person managing the list at > python-list-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. html & python connection problem with hyperlinks > (litssa2...@gmail.com) > 2. Re: Exended ASCII and code pages [was Re: for / while else > doesn't make sense] (Chris Angelico) > 3. Re: for / while else doesn't make sense (Marko Rauhamaa) > 4. Re: Spurious issue in CPython 2.7.5 (thomas povtal.org) > 5. Re: Spurious issue in CPython 2.7.5 (Tim Golden) > 6. Re: for / while else doesn't make sense (Christopher Reimer) > 7. Re: Spurious issue in CPython 2.7.5 (thomas povtal.org) > 8. ValueError: I/O operation on closed file (San) > 9. Re: ValueError: I/O operation on closed file (Joel Goldstick) > 10. Find the max number of elements in lists as value in a > dictionary (Daiyue Weng) > 11. Re: ValueError: I/O operation on closed file (alister) > 12. IndexError for using pandas dataframe values (Daiyue Weng) > 13. Re: Find the max number of elements in lists as value in a > dictionary (Jussi Piitulainen) > 14. Re: Find the max number of elements in lists as value in a > dictionary (Jon Ribbens) > 15. Re: html & python connection problem with hyperlinks > (justin walters) > > > ---------- Forwarded message ---------- > From: litssa2...@gmail.com > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 03:24:30 -0700 (PDT) > Subject: html & python connection problem with hyperlinks > Why not created the field title, that located on the template > BusinessList.html as a link to go to Business_Detail.html..? please check > > Code: > > models. py: > > from django.db import models > > > REGIONS = ( > ('ΘΕΣ', 'ΘΕΣΣΑΛΟΝΙΚΗ'), > ('ΣΕΡ', 'ΣΕΡΡΕΣ'), > ( 'ΑΘΗ', 'ΑΘΗΝΑ'), > > > > TYPEOFBUSINESS = ( > ('ΕΣΤ', 'ΕΣΤΙΑΤΟΡΙΑ'), > ('ΦΑΡ', 'ΦΑΡΜΑΚΕΙΑ'), > ('ΒΙΒ', 'ΒΙΒΛΙΟΠΩΛΕΙΑ'), > ( 'ΚΟΜ', 'ΚΟΜΜΩΤΗΡΙΑ'), > ('ΣΙΝ', 'ΣΙΝΕΜΑ') > > ) > > class Business(models.Model): > created_Date = models.DateTimeField(auto_now_add=True) > owner = models.ForeignKey('auth.User', related_name='snippets', null=True) > title = models.CharField(max_length=100, blank=True, default='') > Type_of_Business = models.CharField(max_length=3, choices=TYPEOFBUSINESS) > region = models.CharField(max_length=3, choices=REGIONS) > address = models.CharField(max_length=100, blank=True, default='') > phone = models.CharField(max_length=15, blank=True, default='') > image = models.ImageField(null=True) > > > def __str__(self): > return str(self.title) > > views.py > > from django.contrib.auth.models import User > from django.http import HttpResponse > from django.shortcuts import render, get_object_or_404 > from rest_framework import filters > from rest_framework import generics > from rest_framework import permissions > from snippets.permissions import IsOwnerOrReadOnly > from snippets.serializers import SnippetSerializer > from snippets.serializers import UserSerializer > from .models import Business > > > > class UserList(generics.ListAPIView): > queryset = User.objects.all() > serializer_class = UserSerializer > > > class UserDetail(generics.RetrieveAPIView): > queryset = User.objects.all() > serializer_class = UserSerializer > > class BusinessList(generics.ListCreateAPIView): > > permission_classes = (permissions.IsAuthenticatedOrReadOnly,) > queryset = Business.objects.all() > serializer_class = SnippetSerializer > filter_backends = (filters.DjangoFilterBackend,filters.SearchFilter, > filters.OrderingFilter,) > filter_fields = ('Type_of_Business', 'region') > search_fields = ('Type_of_Business', 'region') > ordering_fields = ('Type_of_Business','title', 'region') > > > def BusinessList(request): > business = Business.objects.all(); > return render(request, 'snippets/BusinessList.html' {'business':business}) > > def perform_create(self, serializer): > serializer.save(owner=self.request.user) > > > > class Business_Detail(generics.RetrieveUpdateDestroyAPIView): > permission_classes = (permissions.IsAuthenticatedOrReadOnly, > IsOwnerOrReadOnly,) > queryset = Business.objects.all() > serializer_class = SnippetSerializer > > > def Business_Detail(request, pk): > business = get_object_or_404(Business, pk=pk) > return render(request, 'snippets/Business_Detail.html', {'business': > business}) > > serializers.py > > from rest_framework import serializers > from snippets.models import Business > from django.contrib.auth.models import User > > > class SnippetSerializer(serializers.HyperlinkedModelSerializer): > owner = serializers.ReadOnlyField(source='owner.username') > > class Meta: > model = Business > fields = ('created_Date', 'owner', 'title','Type_of_Business', 'region', > 'address', 'phone', 'image') > > > class UserSerializer(serializers.ModelSerializer): > snippets = serializers.PrimaryKeyRelatedField(many=True, > queryset=Business.objects.all()) > > class Meta: > model = User > fields = ('id', 'username', 'snippets') > > BusinessList.html > > {% extends 'snippets/base.html' %} > > {% block content %} > {% for business in business%} > <div class="business"> > <div class="date"> > {{ business.created_Date }} #τυπωσε ημερ.δημιουργιας του Business > </div> > <h1> <a href='{% url 'Business_Detail' pk=business.pk %}'>{{ > business.title }}</a></h1> > <p>{{business.Type_of_Business }}</p> > <h2>{{ business.region }} </h2> > <h3>{{ business.address }} </h3> > <h4>{{ business.phone }} </h4> > {% if business.image %} > <img src="{{ business.image.url }}"/> > {% endif %} > </div> > {% endfor %} > {% endblock %} > > Business_Detail.html > > {% extends 'snippets/base.html' %}' %} > > {% block content %} > <div class="business"> > {% if business.created_Date %} # αν υπαρχει ημερομηνια δημιουργίας > <div class="date"> > {{ business.created_Date }} > </div> > {% endif %} > <h1>{{ business.title }} </h1> > <h2>{{ business.region }} </h2> > <h3>{{ business.Type_of_Business}} </h3> > <h4>{{ business.phone }} </h4> > <p> > {% if business.image %} # αν υπαρχει εικονα > <img src="{{ business.image.url }}"/> # παρε εικονα απο το αντιστοιχο url > {% endif %} > </p> > </div> > {% endblock %} > > tutorial/snippets/urls.py > > from django.conf.urls import url, include > from django.contrib import admin > from rest_framework.urlpatterns import format_suffix_patterns > from django.contrib.staticfiles.urls import staticfiles_urlpatterns > from django.conf.urls import include > > from . import views > > urlpatterns = [ > url(r'^admin/', include(admin.site.urls)), > url(r'^$', views.BusinessList.as_view()), > url(r'^business/(?P<pk>[0-9]+)/$', views.Business_Detail.as_view()), > url(r'^users/$', views.UserList.as_view()), > url(r'^users/(?P<pk>[0-9]+)/$', views.UserDetail.as_view()), > url(r'^api-auth/', include('rest_framework.urls', > namespace='rest_framework')), > > ] > > urlpatterns = format_suffix_patterns(urlpatterns) > urlpatterns += staticfiles_urlpatterns() > > tutorial/urls.py > > from django.conf.urls import include, url > from django.contrib import admin > from django.conf import settings > from django.contrib.staticfiles.urls import staticfiles_urlpatterns > from django.conf.urls.static import static > > > > urlpatterns = [ > url(r'^admin/', include(admin.site.urls)), > url(r'', include('snippets.urls')), > > ] > > urlpatterns += staticfiles_urlpatterns() > urlpatterns += static(settings.PHOTO_URL, > document_root=settings.PHOTO_ROOT) > > > > ---------- Forwarded message ---------- > From: Chris Angelico <ros...@gmail.com> > To: > Cc: "python-list@python.org" <python-list@python.org> > Date: Wed, 25 May 2016 20:30:55 +1000 > Subject: Re: Exended ASCII and code pages [was Re: for / while else > doesn't make sense] > On Wed, May 25, 2016 at 8:19 PM, Steven D'Aprano > <steve+comp.lang.pyt...@pearwood.info> wrote: > > While the code page system was necessary at > > the time, the legacy of them today continues to plague computer users, > causing > > moji-bake, errors on file systems[1], and holding back the adoption of > Unicode. > > > > [1] I'm speaking from experience there. Take files created on a Windows > machine > > using some legacy code page, and try to copy them to another server using > > Unicode, and depending on the intelligence of the server, you may not be > able > > to copy them. On the flip side, there are many file names I can easily > create > > on Linux but cannot copy to a FAT file system. > > And getting a .zip file from a Windows user that had a file in it > called "Café Sounds.something", extracting it on Linux, and finding it > called "Caf\xe9" or something. Very annoying. Fortunately it was only > the one file in a large directory. > > ChrisA > > > > ---------- Forwarded message ---------- > From: Marko Rauhamaa <ma...@pacujo.net> > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 13:47:46 +0300 > Subject: Re: for / while else doesn't make sense > Christopher Reimer <christopher_rei...@icloud.com>: > > > Back in the early 1980's, I grew up on 8-bit processors and latin-1 was > > all we had for ASCII. > > You really were very advanced. According to <URL: > https://en.wikipedia.org/wiki/ISO/IEC_8859-1#History>, ISO 8859-1 was > standardized in 1985. "Eight-bit-cleanness" became a thing in the early > 1990's. > > Where I was in late 1980's, the terminals were still 7-bit, and > instead of ASCII, national 7-bit character set variants were being used. > For example, you might see Pascal code like this: > > ä return the net å > ret := grossÄunitÅ * grossRate > > <URL: http://www.aivosto.com/vbtips/charsets-7bit.html> > > > Over the last several days from reading this thread (and variations > > thereof), l've seen several extended characters that I have no clue on > > how to reproduce on my keyboard. I haven't embraced extended character > > sets yet, which means I still think of ASCII characters as being 0 > > through 255 (8-bit). > > But Latin-1 is on your fingertips? ¡Qué bueno! Entonces sabes dónde > están las teclas españolas, ¿no? > > > Marko > > > > ---------- Forwarded message ---------- > From: "thomas povtal.org" <tho...@povtal.org> > To: python-list <python-list@python.org> > Cc: > Date: Wed, 25 May 2016 14:04:12 +0200 (CEST) > Subject: Re: Spurious issue in CPython 2.7.5 > Hi! > > Thanks. Replies in-line > > Den 24. maj 2016 klokken 19:12 skrev Steven D'Aprano < > st...@pearwood.info>: > > > > On Tue, 24 May 2016 08:22 pm, thomas povtal.org wrote: > > > > > Hi, > > > > > > Please excuse me if this is not the right place, but I have some issues > > > with CPython on a NUMA machine. > > > > Do you mean a Non-Uniform Memory Access machine? > > > > Can you be more specific about the actual machine and OS used? > > It's Ubuntu 12.04 LTS. It appears as a NUMA machine with two nodes. > However, I > later learned that it's (probably?) not a real NUMA but just Ubuntu's way > of > representing two socktets for CPUs. I'm not very skilled in such low-level > matters, unfortunately. > > > 1: I get "RuntimeWarning: tp_compare didn't return -1 or -2 for > > > exception". It's a line like: > > > > > > "if Foo = False:" where Foo is a global variable (global Foo). > > > > What is the type and value of Foo? > > global Foo = False > > > Now, I've searched somewhat on google for indications on when this > > > warning can be seen. However, I haven't really been able to understand > > > why and even if it's significant or not. (At face value I'm nervous the > > > Python runtime environment is corrupted for that process). > > > > At face value, that RuntimeWarning seems to indicate a bug in the > > interpreter. > > Ok. I was fearing this. > > > 2: In my process later on I get: "OverflowError: long too big to > > > convert". > > > > Can you copy and paste the actual traceback rather than retyping it from > > memory? I think you're missing something, namely what the long is being > > converted to. The rest of the traceback will help too. > > 2016-05-24_08:15:40.84187 File "checkrc.pxd", line 14, in > zmq.core.checkrc._check_rc (zmq/core/socket.c:5932) > 2016-05-24_08:15:40.84187 OverflowError: long too big to convert > > I agree it looks like cut off, but it isn't... > > > This happens in different places and seems to always relate to > > > obtaining a length of something (dict or list created by list > > > comprehension). Fx > > > > > > "for i in xrange(0, len_of_stuff, max_section_size):" > > > > > > en_of_stuff is always less than the max long (around 600). > > > > What do you mean, "the max long"? Longs do not have a max value. The only > > limit is the amount of memory you have. > > > > What about max_section_size? How big is that? > > 30 > > > We're using gevent and I'm suspecting some "threading" could cause > > > this, as I'm able to replicate it locally with the same data. > > > > Typo: you said later that you are *not* able to replicate it. > > > > You're using a global variable with threaded code? You're a brave (or > > foolhardy) man... > > Yeah, I didn't write the code originally, but that's not an excuse. The > greenlets involved doesn't appear to be mulithreaded in this case, though. > Even > if it was, could that miss with the interpreter to give these sporious > messages? > > -- > > Steven > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > ---------- Forwarded message ---------- > From: Tim Golden <m...@timgolden.me.uk> > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 13:13:49 +0100 > Subject: Re: Spurious issue in CPython 2.7.5 > On 25/05/2016 13:04, thomas povtal.org wrote: > > 2016-05-24_08:15:40.84187 File "checkrc.pxd", line 14, in > > zmq.core.checkrc._check_rc (zmq/core/socket.c:5932) > > 2016-05-24_08:15:40.84187 OverflowError: long too big to convert > > That exception is arising from ZeroMQ's own code, by the look of it. (Or > perhaps pyzmq). > > It's not impossible that it's arising ultimately from Python's > interpreter core, but you'd want to take that up with the ZeroMQ guys > first to see what checks they're doing which might raise that exception. > > https://github.com/zeromq > > TJG > > > > ---------- Forwarded message ---------- > From: Christopher Reimer <christopher_rei...@icloud.com> > To: Marko Rauhamaa <ma...@pacujo.net> > Cc: python-list@python.org > Date: Wed, 25 May 2016 05:19:01 -0700 > Subject: Re: for / while else doesn't make sense > > On May 25, 2016, at 3:47 AM, Marko Rauhamaa <ma...@pacujo.net> wrote: > > > > Christopher Reimer <christopher_rei...@icloud.com>: > > > >> Back in the early 1980's, I grew up on 8-bit processors and latin-1 was > >> all we had for ASCII. > > > > You really were very advanced. According to <URL: > > https://en.wikipedia.org/wiki/ISO/IEC_8859-1#History>, ISO 8859-1 was > > standardized in 1985. "Eight-bit-cleanness" became a thing in the early > > 1990's. > > Apparently, I wasn't. According to the Internet, which can't be wrong, > many of the 8-bit computers in the early 1980's were based on 1960's ASCII > with some non-standard characters tossed in. Latin-1 probably came during > my DOS days in the 1990's. > > As for ISO 8859-1, the standard was approved in 1985 but it was based on > the character set for the first ANSI standard terminal, DEC VT-2200, that > came out in 1983. Still early 1980's. ;) > > Thank you, > > Chris R. > > > ---------- Forwarded message ---------- > From: "thomas povtal.org" <tho...@povtal.org> > To: Tim Golden <m...@timgolden.me.uk>, python-list <python-list@python.org > > > Cc: > Date: Wed, 25 May 2016 14:26:33 +0200 (CEST) > Subject: Re: Spurious issue in CPython 2.7.5 > Hi! > > Thanks. It was an example... I get the very same exception text (the one > that appears to be cut off) in this line in our own code: > > if Foo == False: > > (where Foo is global Foo = False.) > > :) T > > Den 25. maj 2016 klokken 14:13 skrev Tim Golden <m...@timgolden.me.uk > >: > > On 25/05/2016 13:04, thomas povtal.org wrote: > > 2016-05-24_08:15:40.84187 File "checkrc.pxd", line 14, in > > zmq.core.checkrc._check_rc (zmq/core/socket.c:5932) > > 2016-05-24_08:15:40.84187 OverflowError: long too big to convert > > That exception is arising from ZeroMQ's own code, by the look of it. > (Or > perhaps pyzmq). > > It's not impossible that it's arising ultimately from Python's > interpreter core, but you'd want to take that up with the ZeroMQ guys > first to see what checks they're doing which might raise that > exception. > > https://github.com/zeromq > > TJG > -- > https://mail.python.org/mailman/listinfo/python-list > > > > ---------- Forwarded message ---------- > From: San <santan...@gmail.com> > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 05:29:53 -0700 (PDT) > Subject: ValueError: I/O operation on closed file > Hi Gorup, > > why i am getting "ValueError: I/O operation on closed file" this error. > Pls let me know. > > Thanks in Advance. > san > > > > ---------- Forwarded message ---------- > From: Joel Goldstick <joel.goldst...@gmail.com> > To: > Cc: "python-list@python.org" <python-list@python.org> > Date: Wed, 25 May 2016 09:12:33 -0400 > Subject: Re: ValueError: I/O operation on closed file > On Wed, May 25, 2016 at 8:29 AM, San <santan...@gmail.com> wrote: > > Hi Gorup, > > > > why i am getting "ValueError: I/O operation on closed file" this error. > > Pls let me know. > > Because your program is incorrect? > > Why not list your code, so that someone might be able to help you? > > > > > > Thanks in Advance. > > san > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays > > > > ---------- Forwarded message ---------- > From: Daiyue Weng <daiyuew...@gmail.com> > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 14:32:34 +0100 > Subject: Find the max number of elements in lists as value in a dictionary > I want to find the maximal number of elements contained in a nested > dictionary, e.g. > > data = { > 'violations': > { > 'col1': {'err': [elem1, elem2, elem3]}, > 'col2': {'err': [elem1, elem2]} > } > } > > so to find the maximal number of elements in the lists for key 'err' in key > 'col1' and 'col2'. Also key 'violations' may contain many keys (e.g. 'col1' > , 'col2', 'col3' etc), so what's the best way to do this (using a loop)? > > max = 0for col in data.violations: > if max < len(data.violations.col.err): > max = len(data.violations.col.err) > > > cheers > > > > ---------- Forwarded message ---------- > From: alister <alister.w...@ntlworld.com> > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 14:03:17 GMT > Subject: Re: ValueError: I/O operation on closed file > On Wed, 25 May 2016 05:29:53 -0700, San wrote: > > > Hi Gorup, > > > > why i am getting "ValueError: I/O operation on closed file" this error. > > Pls let me know. > > > > Thanks in Advance. > > san > > because you are trying to do something with a file that has been closed > > the error message is quite explanatory > > > -- > One friend in a lifetime is much; two are many; three are hardly possible. > Friendship needs a certain parallelism of life, a community of thought, > a rivalry of aim. > -- Henry Brook Adams > > > > ---------- Forwarded message ---------- > From: Daiyue Weng <daiyuew...@gmail.com> > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 15:19:13 +0100 > Subject: IndexError for using pandas dataframe values > Hi, I tried to use DataFrame.values to convert a list of columns in a > dataframe to a numpy ndarray/matrix, > > matrix = df.values[:, list_of_cols] > > but got an error, > > IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis > (None) and integer or boolean arrays are valid indices > > so what's the problem with the list of columns I passed in? > > many thanks > > > > ---------- Forwarded message ---------- > From: Jussi Piitulainen <jussi.piitulai...@helsinki.fi> > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 17:24:10 +0300 > Subject: Re: Find the max number of elements in lists as value in a > dictionary > Daiyue Weng writes: > > > I want to find the maximal number of elements contained in a nested > > dictionary, e.g. > > > > data = { > > 'violations': > > { > > 'col1': {'err': [elem1, elem2, elem3]}, > > 'col2': {'err': [elem1, elem2]} > > } > > } > > > > so to find the maximal number of elements in the lists for key 'err' in > key > > 'col1' and 'col2'. Also key 'violations' may contain many keys (e.g. > 'col1' > > , 'col2', 'col3' etc), so what's the best way to do this (using a loop)? > > > > max = 0for col in data.violations: > > if max < len(data.violations.col.err): > > max = len(data.violations.col.err) > > Write a generator function that produces an object that generates the > lengths. The magic word is the "yield" which is used like "return" but > makes it so that the resulting objects yields each value on demand. For > greater magic, make it yield the path to each list together with the > length (length first, for easy max): > > def errcounts(data): > for top, sub in data.items(): > for mid, wev in sub.items(): > if 'err' in wev: > yield (len(wev['err']), top, mid) > > With that, Python's max does it all: > > max(errcounts(data)) => (3, 'violations', 'col1') > > This anticipated a next question; tuple comparison is overly specific; > use a key function to max to not overspecify if you care; max needs a > default in case there is no data; this same thing can be done with a > single "generator expression" and that might be good, depending on the > actual details and taste. Many other caveats apply. > > > > ---------- Forwarded message ---------- > From: Jon Ribbens <jon+use...@unequivocal.co.uk> > To: python-list@python.org > Cc: > Date: Wed, 25 May 2016 14:28:42 -0000 (UTC) > Subject: Re: Find the max number of elements in lists as value in a > dictionary > On 2016-05-25, Daiyue Weng <daiyuew...@gmail.com> wrote: > > I want to find the maximal number of elements contained in a nested > > dictionary, e.g. > > > > data = { > > 'violations': > > { > > 'col1': {'err': [elem1, elem2, elem3]}, > > 'col2': {'err': [elem1, elem2]} > > } > > } > > > > so to find the maximal number of elements in the lists for key 'err' in > key > > 'col1' and 'col2'. Also key 'violations' may contain many keys (e.g. > 'col1' > > , 'col2', 'col3' etc), so what's the best way to do this (using a loop)? > > > > max = 0for col in data.violations: > > if max < len(data.violations.col.err): > > max = len(data.violations.col.err) > > In Python 3 you could do: > > max((len(col["err"]) for col in data["violations"].values()), default=0) > > In Python 2 you can do the same but you can't specify "default=0" and > so it will throw an exception if there are no lists found, so you > could use something like: > > max_errs = 0 > if data["violations"]: > max_errs = max(len(col["err"]) for col in > data["violations"].values()) > > > > ---------- Forwarded message ---------- > From: justin walters <walters.justi...@gmail.com> > To: litssa2...@gmail.com > Cc: python-list@python.org > Date: Wed, 25 May 2016 08:06:27 -0700 > Subject: Re: html & python connection problem with hyperlinks > On Wed, May 25, 2016 at 3:24 AM, <litssa2...@gmail.com> wrote: > > > Why not created the field title, that located on the template > > BusinessList.html as a link to go to Business_Detail.html..? please check > > > > Code: > > > > models. py: > > > > from django.db import models > > > > > > REGIONS = ( > > ('ΘΕΣ', 'ΘΕΣΣΑΛΟΝΙΚΗ'), > > ('ΣΕΡ', 'ΣΕΡΡΕΣ'), > > ( 'ΑΘΗ', 'ΑΘΗΝΑ'), > > > > > > > > TYPEOFBUSINESS = ( > > ('ΕΣΤ', 'ΕΣΤΙΑΤΟΡΙΑ'), > > ('ΦΑΡ', 'ΦΑΡΜΑΚΕΙΑ'), > > ('ΒΙΒ', 'ΒΙΒΛΙΟΠΩΛΕΙΑ'), > > ( 'ΚΟΜ', 'ΚΟΜΜΩΤΗΡΙΑ'), > > ('ΣΙΝ', 'ΣΙΝΕΜΑ') > > > > ) > > > > class Business(models.Model): > > created_Date = models.DateTimeField(auto_now_add=True) > > owner = models.ForeignKey('auth.User', related_name='snippets', > null=True) > > title = models.CharField(max_length=100, blank=True, default='') > > Type_of_Business = models.CharField(max_length=3, choices=TYPEOFBUSINESS) > > region = models.CharField(max_length=3, choices=REGIONS) > > address = models.CharField(max_length=100, blank=True, default='') > > phone = models.CharField(max_length=15, blank=True, default='') > > image = models.ImageField(null=True) > > > > > > def __str__(self): > > return str(self.title) > > > > views.py > > > > from django.contrib.auth.models import User > > from django.http import HttpResponse > > from django.shortcuts import render, get_object_or_404 > > from rest_framework import filters > > from rest_framework import generics > > from rest_framework import permissions > > from snippets.permissions import IsOwnerOrReadOnly > > from snippets.serializers import SnippetSerializer > > from snippets.serializers import UserSerializer > > from .models import Business > > > > > > > > class UserList(generics.ListAPIView): > > queryset = User.objects.all() > > serializer_class = UserSerializer > > > > > > class UserDetail(generics.RetrieveAPIView): > > queryset = User.objects.all() > > serializer_class = UserSerializer > > > > class BusinessList(generics.ListCreateAPIView): > > > > permission_classes = (permissions.IsAuthenticatedOrReadOnly,) > > queryset = Business.objects.all() > > serializer_class = SnippetSerializer > > filter_backends = (filters.DjangoFilterBackend,filters.SearchFilter, > > filters.OrderingFilter,) > > filter_fields = ('Type_of_Business', 'region') > > search_fields = ('Type_of_Business', 'region') > > ordering_fields = ('Type_of_Business','title', 'region') > > > > > > def BusinessList(request): > > business = Business.objects.all(); > > return render(request, 'snippets/BusinessList.html' > {'business':business}) > > > > def perform_create(self, serializer): > > serializer.save(owner=self.request.user) > > > > > > > > class Business_Detail(generics.RetrieveUpdateDestroyAPIView): > > permission_classes = (permissions.IsAuthenticatedOrReadOnly, > > IsOwnerOrReadOnly,) > > queryset = Business.objects.all() > > serializer_class = SnippetSerializer > > > > > > def Business_Detail(request, pk): > > business = get_object_or_404(Business, pk=pk) > > return render(request, 'snippets/Business_Detail.html', {'business': > > business}) > > > > serializers.py > > > > from rest_framework import serializers > > from snippets.models import Business > > from django.contrib.auth.models import User > > > > > > class SnippetSerializer(serializers.HyperlinkedModelSerializer): > > owner = serializers.ReadOnlyField(source='owner.username') > > > > class Meta: > > model = Business > > fields = ('created_Date', 'owner', 'title','Type_of_Business', 'region', > > 'address', 'phone', 'image') > > > > > > class UserSerializer(serializers.ModelSerializer): > > snippets = serializers.PrimaryKeyRelatedField(many=True, > > queryset=Business.objects.all()) > > > > class Meta: > > model = User > > fields = ('id', 'username', 'snippets') > > > > BusinessList.html > > > > {% extends 'snippets/base.html' %} > > > > {% block content %} > > {% for business in business%} > > <div class="business"> > > <div class="date"> > > {{ business.created_Date }} #τυπωσε ημερ.δημιουργιας του Business > > </div> > > <h1> <a href='{% url 'Business_Detail' pk=business.pk %}'>{{ > > business.title }}</a></h1> > > <p>{{business.Type_of_Business }}</p> > > <h2>{{ business.region }} </h2> > > <h3>{{ business.address }} </h3> > > <h4>{{ business.phone }} </h4> > > {% if business.image %} > > <img src="{{ business.image.url }}"/> > > {% endif %} > > </div> > > {% endfor %} > > {% endblock %} > > > > Business_Detail.html > > > > {% extends 'snippets/base.html' %}' %} > > > > {% block content %} > > <div class="business"> > > {% if business.created_Date %} # αν υπαρχει ημερομηνια δημιουργίας > > <div class="date"> > > {{ business.created_Date }} > > </div> > > {% endif %} > > <h1>{{ business.title }} </h1> > > <h2>{{ business.region }} </h2> > > <h3>{{ business.Type_of_Business}} </h3> > > <h4>{{ business.phone }} </h4> > > <p> > > {% if business.image %} # αν υπαρχει εικονα > > <img src="{{ business.image.url }}"/> # παρε εικονα απο το αντιστοιχο url > > {% endif %} > > </p> > > </div> > > {% endblock %} > > > > tutorial/snippets/urls.py > > > > from django.conf.urls import url, include > > from django.contrib import admin > > from rest_framework.urlpatterns import format_suffix_patterns > > from django.contrib.staticfiles.urls import staticfiles_urlpatterns > > from django.conf.urls import include > > > > from . import views > > > > urlpatterns = [ > > url(r'^admin/', include(admin.site.urls)), > > url(r'^$', views.BusinessList.as_view()), > > url(r'^business/(?P<pk>[0-9]+)/$', views.Business_Detail.as_view()), > > url(r'^users/$', views.UserList.as_view()), > > url(r'^users/(?P<pk>[0-9]+)/$', views.UserDetail.as_view()), > > url(r'^api-auth/', include('rest_framework.urls', > > namespace='rest_framework')), > > > > ] > > > > urlpatterns = format_suffix_patterns(urlpatterns) > > urlpatterns += staticfiles_urlpatterns() > > > > tutorial/urls.py > > > > from django.conf.urls import include, url > > from django.contrib import admin > > from django.conf import settings > > from django.contrib.staticfiles.urls import staticfiles_urlpatterns > > from django.conf.urls.static import static > > > > > > > > urlpatterns = [ > > url(r'^admin/', include(admin.site.urls)), > > url(r'', include('snippets.urls')), > > > > ] > > > > urlpatterns += staticfiles_urlpatterns() > > urlpatterns += static(settings.PHOTO_URL, > > document_root=settings.PHOTO_ROOT) > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > There are two problems here. You need to define a namespace for > snippets.urls in tutorials/urls.py: > > url(r'', include('snippets.urls', namespace='snippets')) > > You also need to give a name to your detail view in snippets/urls.py. Also, > you do not need to call 'as_view() on function based views like business > detail: > > url(r'^business/(?P<pk>[0-9]+)/$, views.business_detail, > name='business_detail') > > Then, in your list template you can do the following: > > <h1><a href="{% url 'snippets:business_detail' pk=business.pk > %}">{{business.title}}</a></h1> > > This will create a linked h1 tag that links to the business detail page. > > Hope this helps. > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list