Re: trying to use a variable inside a static content tag

2019-07-27 Thread Sipum Mishra
Hi Lyman,

PFB.

Configure the following setting in your setting.py

STATIC_ROOT = os.path.join(BASE_DIR,"static_files")
STATIC_URL = '/static/'

STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),)

load *staticfiles* tag to template

{% load staticfiles %}

and then use in *src* attribute of *img HTML tag as you did. *


On Sun, 28 Jul, 2019, 4:37 AM Sithembewena L. Dube, 
wrote:

> Interesting.
>
> Kind regards,
> Lloyd
>
>
> *Sent with Shift
> *
>
> On Sat, Jul 27, 2019 at 11:25 PM Lyman Hurd  wrote:
>
>> A helpful user in the Python #django slack channel showed me this answer:
>>
>>
>> https://stackoverflow.com/questions/16655851/django-1-5-how-to-use-variables-inside-static-tag
>>
>>
>> On Saturday, July 20, 2019 at 4:31:52 AM UTC-7, Lyman Hurd wrote:
>>>
>>> Greetings.  I am writing a card game and I can load an image when I give
>>> a fixed value such as:
>>>
>>> >> style="width:69px;height:106px;">
>>>
>>> but I would actually like part o fthis to be determined by a tag (there
>>> is a for loop setting values) but when I write:
>>>
>>> >> style="width:69px;height:106px;">
>>>
>>> however when this is rendered into HTML the tag {{ card }} ha sbeen
>>> URL-escaped:
>>>
>>> 
>>>
>>> How can I render a static image based on the contents of a tag?
>>>
>>>
>>> Cheers,
>>>
>>> Lyman Hurd
>>>
>>>
>>> --
>> 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/6706118e-f64a-4c6d-8bc6-c558d48640f5%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/CAH-SnCCtH6%3DP6rzezAk1ErTaFnhYyVmBNj82wGN4osw%3DPeEdFA%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGHZBzwSf04Cao6xzYumTZWOoDqqEUF7J4moHGHx3tkU0SQVSQ%40mail.gmail.com.


Re: trying to use a variable inside a static content tag

2019-07-27 Thread Sithembewena L. Dube
Interesting.

Kind regards,
Lloyd


*Sent with Shift
*

On Sat, Jul 27, 2019 at 11:25 PM Lyman Hurd  wrote:

> A helpful user in the Python #django slack channel showed me this answer:
>
>
> https://stackoverflow.com/questions/16655851/django-1-5-how-to-use-variables-inside-static-tag
>
>
> On Saturday, July 20, 2019 at 4:31:52 AM UTC-7, Lyman Hurd wrote:
>>
>> Greetings.  I am writing a card game and I can load an image when I give
>> a fixed value such as:
>>
>> > style="width:69px;height:106px;">
>>
>> but I would actually like part o fthis to be determined by a tag (there
>> is a for loop setting values) but when I write:
>>
>> > style="width:69px;height:106px;">
>>
>> however when this is rendered into HTML the tag {{ card }} ha sbeen
>> URL-escaped:
>>
>> 
>>
>> How can I render a static image based on the contents of a tag?
>>
>>
>> Cheers,
>>
>> Lyman Hurd
>>
>>
>> --
> 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/6706118e-f64a-4c6d-8bc6-c558d48640f5%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/CAH-SnCCtH6%3DP6rzezAk1ErTaFnhYyVmBNj82wGN4osw%3DPeEdFA%40mail.gmail.com.


Re: trying to use a variable inside a static content tag

2019-07-27 Thread Lyman Hurd
A helpful user in the Python #django slack channel showed me this answer:

https://stackoverflow.com/questions/16655851/django-1-5-how-to-use-variables-inside-static-tag


On Saturday, July 20, 2019 at 4:31:52 AM UTC-7, Lyman Hurd wrote:
>
> Greetings.  I am writing a card game and I can load an image when I give a 
> fixed value such as:
>
>  style="width:69px;height:106px;">
>
> but I would actually like part o fthis to be determined by a tag (there is 
> a for loop setting values) but when I write:
>
>  style="width:69px;height:106px;">
>
> however when this is rendered into HTML the tag {{ card }} ha sbeen 
> URL-escaped:
>
> 
>
> How can I render a static image based on the contents of a tag?
>
>
> Cheers,
>
> Lyman Hurd
>
>
>

-- 
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/6706118e-f64a-4c6d-8bc6-c558d48640f5%40googlegroups.com.


Model Related Issue

2019-07-27 Thread Soumen Khatua
Hi Folks,
I created one Address model and I extended Profile model by using
OnetoOneField of User and this Address model. But in get method  I want to
provide User model email,username and Address model state and Profile model
all details,How I can do that ny using Django Rest Framework.
Please help me guys,It's Urgent??


Thank You

-- 
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/CAPUw6WYeumcAXc_zn6or05S5EvvEizeMXLcnFkJnbsXHB6CG8A%40mail.gmail.com.


Django Project Server not starting when running on linux server but running on local windows desktop

2019-07-27 Thread Top Dolla
Agreed. Make sure the Python and Django versions are identical.

-- 
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/06befc90-b58c-48c2-9927-94f8b55e8897%40googlegroups.com.


Re: Overriding methods in models of other developers

2019-07-27 Thread Jani Tiainen
You  can do that with proxy models which allows you to override and add
methods.

Of course if there is a need to really modify original model it gets tricky.

la 27. heinäk. 2019 klo 10.49 אורי  kirjoitti:

> Hi,
>
> I had to change the following lines because tests failed:
>
> class Friend1(object):
> def __str__(self):
> return "User {} is friends with {}".format(self.to_user, 
> self.from_user)
>
>
> class FriendshipRequest1(object):
> def __str__(self):
> return "Friendship request from user {} to {}".format(self.from_user, 
> self.to_user)
>
>
> Friend.__str__ = Friend1.__str__
> FriendshipRequest.__str__ = FriendshipRequest1.__str__
>
>
> אורי
> u...@speedy.net
>
>
> ‪On Sat, Jul 27, 2019 at 9:26 AM ‫אורי‬‎  wrote:‬
>
>> Django users,
>>
>> I want to override def __str__ of models I'm using, but the models are
>> maintained by other developers. I think the __str__ is only used by the
>> admin interface. I found out that I can do something like this:
>>
>> from django.contrib import admin
>> from django.contrib.sites.models import Site
>> from django.contrib.auth.models import Group
>>
>> from friendship.models import Follow, Friend, FriendshipRequest, Block
>>
>>
>> class ReadOnlyModelAdmin(admin.ModelAdmin):
>> """
>> ModelAdmin class that prevents modifications through the admin.
>>
>> The changelist and the detail view work, but a 403 is returned
>> if one actually tries to edit an object.
>> """
>> actions = None
>>
>> # We cannot call super().get_fields(request, obj) because that method 
>> calls
>> # get_readonly_fields(request, obj), causing infinite recursion. Ditto 
>> for
>> # super().get_form(request, obj). So we assume the default ModelForm.
>> def get_readonly_fields(self, request, obj=None):
>> return self.fields or [f.name for f in self.model._meta.fields]
>>
>> def has_add_permission(self, request):
>> return False
>>
>> # Allow viewing objects but not actually changing them.
>> def has_change_permission(self, request, obj=None):
>> return (request.method in ['GET', 'HEAD'] and 
>> super().has_change_permission(request, obj))
>>
>> def has_delete_permission(self, request, obj=None):
>> return False
>>
>>
>> admin.site.unregister(Site)
>> admin.site.register(Site, ReadOnlyModelAdmin)
>>
>> admin.site.unregister(Group)
>> # admin.site.register(Group, ReadOnlyModelAdmin)
>>
>> admin.site.unregister(Block)
>> admin.site.unregister(Follow)
>> admin.site.unregister(Friend)
>> admin.site.unregister(FriendshipRequest)
>> # admin.site.register(Block, ReadOnlyModelAdmin)
>> # admin.site.register(Follow, ReadOnlyModelAdmin)
>> admin.site.register(Friend, ReadOnlyModelAdmin)
>> admin.site.register(FriendshipRequest, ReadOnlyModelAdmin)
>>
>>
>> class Friend1(Friend):
>> def __str__(self):
>> return "User {} is friends with {}".format(self.to_user, 
>> self.from_user)
>>
>>
>> class FriendshipRequest1(FriendshipRequest):
>> def __str__(self):
>> return "Friendship request from user {} to 
>> {}".format(self.from_user, self.to_user)
>>
>>
>> Friend.__str__ = Friend1.__str__
>> FriendshipRequest.__str__ = FriendshipRequest1.__str__
>>
>> But, is it possible override __str__ in a cleaner way? It seems to me not
>> such a clean way to override a method (but it works). But I have to use the
>> model itself, because there is a lot of code in the package I'm using that
>> uses the model itself.
>>
>> (We are using our own Block model which I think we developed before they
>> developed a similar model. We are not using their Follow model too).
>>
>> אורי
>> u...@speedy.net
>>
> --
> 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/CABD5YeHNUEozN0vg_M5Hz9QrCTUAzH--u9SHtPVeDvJ4ZgWeOA%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91odhu6Dtaxq%3DtVA5vmWSPmJUyRL42o--h--awBm3BHVjpw%40mail.gmail.com.


Re: Overriding methods in models of other developers

2019-07-27 Thread אורי
Hi,

I had to change the following lines because tests failed:

class Friend1(object):
def __str__(self):
return "User {} is friends with {}".format(self.to_user, self.from_user)


class FriendshipRequest1(object):
def __str__(self):
return "Friendship request from user {} to
{}".format(self.from_user, self.to_user)


Friend.__str__ = Friend1.__str__
FriendshipRequest.__str__ = FriendshipRequest1.__str__


אורי
u...@speedy.net


‪On Sat, Jul 27, 2019 at 9:26 AM ‫אורי‬‎  wrote:‬

> Django users,
>
> I want to override def __str__ of models I'm using, but the models are
> maintained by other developers. I think the __str__ is only used by the
> admin interface. I found out that I can do something like this:
>
> from django.contrib import admin
> from django.contrib.sites.models import Site
> from django.contrib.auth.models import Group
>
> from friendship.models import Follow, Friend, FriendshipRequest, Block
>
>
> class ReadOnlyModelAdmin(admin.ModelAdmin):
> """
> ModelAdmin class that prevents modifications through the admin.
>
> The changelist and the detail view work, but a 403 is returned
> if one actually tries to edit an object.
> """
> actions = None
>
> # We cannot call super().get_fields(request, obj) because that method 
> calls
> # get_readonly_fields(request, obj), causing infinite recursion. Ditto for
> # super().get_form(request, obj). So we assume the default ModelForm.
> def get_readonly_fields(self, request, obj=None):
> return self.fields or [f.name for f in self.model._meta.fields]
>
> def has_add_permission(self, request):
> return False
>
> # Allow viewing objects but not actually changing them.
> def has_change_permission(self, request, obj=None):
> return (request.method in ['GET', 'HEAD'] and 
> super().has_change_permission(request, obj))
>
> def has_delete_permission(self, request, obj=None):
> return False
>
>
> admin.site.unregister(Site)
> admin.site.register(Site, ReadOnlyModelAdmin)
>
> admin.site.unregister(Group)
> # admin.site.register(Group, ReadOnlyModelAdmin)
>
> admin.site.unregister(Block)
> admin.site.unregister(Follow)
> admin.site.unregister(Friend)
> admin.site.unregister(FriendshipRequest)
> # admin.site.register(Block, ReadOnlyModelAdmin)
> # admin.site.register(Follow, ReadOnlyModelAdmin)
> admin.site.register(Friend, ReadOnlyModelAdmin)
> admin.site.register(FriendshipRequest, ReadOnlyModelAdmin)
>
>
> class Friend1(Friend):
> def __str__(self):
> return "User {} is friends with {}".format(self.to_user, 
> self.from_user)
>
>
> class FriendshipRequest1(FriendshipRequest):
> def __str__(self):
> return "Friendship request from user {} to {}".format(self.from_user, 
> self.to_user)
>
>
> Friend.__str__ = Friend1.__str__
> FriendshipRequest.__str__ = FriendshipRequest1.__str__
>
> But, is it possible override __str__ in a cleaner way? It seems to me not
> such a clean way to override a method (but it works). But I have to use the
> model itself, because there is a lot of code in the package I'm using that
> uses the model itself.
>
> (We are using our own Block model which I think we developed before they
> developed a similar model. We are not using their Follow model too).
>
> אורי
> u...@speedy.net
>

-- 
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/CABD5YeHNUEozN0vg_M5Hz9QrCTUAzH--u9SHtPVeDvJ4ZgWeOA%40mail.gmail.com.


Re: Django Project Server not starting when running on linux server but running on local windows desktop

2019-07-27 Thread Jorge Gimeno
On Fri, Jul 26, 2019, 8:22 PM Abhijith E  wrote:

> It's the latest version.
> Also I am using Anaconda Distribution with Python 3.5
>
> On Sat, Jul 27, 2019, 8:44 AM Jorge Gimeno  wrote:
>
>> What version of Django are you running?
>>
>> On Fri, Jul 26, 2019, 7:34 AM abhijithez  wrote:
>>
>>> Hi All,
>>>
>>> I have created a Django Project that is working fine on local desktop
>>> but when I am starting the same on linux server using python manage.py
>>> runserver it shows the following:
>>>
>>> $python manage.py runserver
>>>
>>> Watching for file changes with StatReloader
>>> Performing system checks...
>>> System check identified no issues (0 silenced).
>>> Traceback (most recent call last):
>>>   File "manage.py", line 21, in 
>>> main()
>>>   File "manage.py", line 17, in main
>>> execute_from_command_line(sys.argv)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/core/managemen
>>>
>>>
>>>t/__init__.py", line 381, in execute_from_command_line
>>> utility.execute()
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/core/managemen
>>>
>>>
>>>t/__init__.py", line 375, in execute
>>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/core/managemen
>>>
>>>
>>>t/base.py", line 323, in run_from_argv
>>> self.execute(*args, **cmd_options)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/core/managemen
>>>
>>>
>>>t/commands/runserver.py", line 60, in execute
>>> super().execute(*args, **options)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/core/managemen
>>>
>>>
>>>t/base.py", line 364, in execute
>>> output = self.handle(*args, **options)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/core/managemen
>>>
>>>
>>>t/commands/runserver.py", line 95, in handle
>>> self.run(**options)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/core/managemen
>>>
>>>
>>>t/commands/runserver.py", line 102, in run
>>> autoreload.run_with_reloader(self.inner_run, **options)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 587, in run_with_reloader
>>> start_django(reloader, main_func, *args, **kwargs)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 572, in start_django
>>> reloader.run(django_main_thread)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 290, in run
>>> self.run_loop()
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 296, in run_loop
>>> next(ticker)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 336, in tick
>>> for filepath, mtime in self.snapshot_files():
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 352, in snapshot_files
>>> for file in self.watched_files():
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 251, in watched_files
>>> yield from iter_all_python_module_files()
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 103, in iter_all_python_module_files
>>> return iter_modules_and_files(modules, frozenset(_error_files))
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/django/utils/autorelo
>>>
>>>
>>>ad.py", line 116, in iter_modules_and_files
>>> if module.__name__ == '__main__':
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/py/_apipkg.py", line
>>>
>>>
>>>   171, in __getattribute__
>>> return getattr(getmod(), name)
>>>   File
>>> "/home/mluser/anaconda3/lib/python3.5/site-packages/py/_error.py", line 4
>>>
>>>
>>>3, in __getattr__
>>> raise AttributeError(name)
>>> AttributeError: __name__
>>>
>>> What could be the issue?
>>>
>>> --
>>> 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/b2e867f4-3d12-4a5e-b035-cabc7419e294%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 

Re: Problem with running Django with nginx and uwsgi in Ubuntu

2019-07-27 Thread אורי
Thanks for your suggestions, I'll try it.
אורי
u...@speedy.net

>
>

-- 
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/CABD5YeErK%3Dg0MMdA-Oq6UDv73H8Z8SzqGfXsvYENTg3tM8-5PA%40mail.gmail.com.


Overriding methods in models of other developers

2019-07-27 Thread אורי
Django users,

I want to override def __str__ of models I'm using, but the models are
maintained by other developers. I think the __str__ is only used by the
admin interface. I found out that I can do something like this:

from django.contrib import admin
from django.contrib.sites.models import Site
from django.contrib.auth.models import Group

from friendship.models import Follow, Friend, FriendshipRequest, Block


class ReadOnlyModelAdmin(admin.ModelAdmin):
"""
ModelAdmin class that prevents modifications through the admin.

The changelist and the detail view work, but a 403 is returned
if one actually tries to edit an object.
"""
actions = None

# We cannot call super().get_fields(request, obj) because that method calls
# get_readonly_fields(request, obj), causing infinite recursion. Ditto for
# super().get_form(request, obj). So we assume the default ModelForm.
def get_readonly_fields(self, request, obj=None):
return self.fields or [f.name for f in self.model._meta.fields]

def has_add_permission(self, request):
return False

# Allow viewing objects but not actually changing them.
def has_change_permission(self, request, obj=None):
return (request.method in ['GET', 'HEAD'] and
super().has_change_permission(request, obj))

def has_delete_permission(self, request, obj=None):
return False


admin.site.unregister(Site)
admin.site.register(Site, ReadOnlyModelAdmin)

admin.site.unregister(Group)
# admin.site.register(Group, ReadOnlyModelAdmin)

admin.site.unregister(Block)
admin.site.unregister(Follow)
admin.site.unregister(Friend)
admin.site.unregister(FriendshipRequest)
# admin.site.register(Block, ReadOnlyModelAdmin)
# admin.site.register(Follow, ReadOnlyModelAdmin)
admin.site.register(Friend, ReadOnlyModelAdmin)
admin.site.register(FriendshipRequest, ReadOnlyModelAdmin)


class Friend1(Friend):
def __str__(self):
return "User {} is friends with {}".format(self.to_user, self.from_user)


class FriendshipRequest1(FriendshipRequest):
def __str__(self):
return "Friendship request from user {} to
{}".format(self.from_user, self.to_user)


Friend.__str__ = Friend1.__str__
FriendshipRequest.__str__ = FriendshipRequest1.__str__

But, is it possible override __str__ in a cleaner way? It seems to me not
such a clean way to override a method (but it works). But I have to use the
model itself, because there is a lot of code in the package I'm using that
uses the model itself.

(We are using our own Block model which I think we developed before they
developed a similar model. We are not using their Follow model too).

אורי
u...@speedy.net

-- 
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/CABD5YeFkjgbYD0vatfC3%3DAQ8zKCYYNkwdNgpCdd6_%3DiEkc6dgA%40mail.gmail.com.