These are chat archives for django/django

Dec 2016
Carlos Azuaje
Dec 01 2016 01:43
What is the best way to control my view of like_longboard , I'm using ajax and I want to prevent users from clicking on the same product and generating more than 1 "like" ?
def like_longboard(request):
    longboard_id = request.GET.get('longboard_id', None)

    likes = 0
    if (longboard_id):
        longboard = Longboard.objects.get(id=int(longboard_id))
        if longboard is not None:
            likes = longboard.likes + 1
            longboard.likes = likes
    return HttpResponse(likes)
Dec 01 2016 06:58
last time I did it I used many-to-many field
users_like = models.ManyToManyField(
on the thing that I wanted to get likes for
aaaand an api call that would be received on "like”-request:
@permission_classes((IsAuthenticated, ))
def question_like(request, pk):
    if request.method == 'POST':
            question = Question.objects.get(pk=pk)
        except Question.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)
        profile = Profile.objects.get(user=request.user)
        if profile not in question.users_like.all():
        return Response(status=status.HTTP_200_OK)
Dennis Decoene
Dec 01 2016 09:49
Hello, has anyone had this: I run a django app on windows, started as a service that I made with SRVMAN. I installed miniconda2 and the exec of the service is: C:\Program Files\Miniconda2\envs\test\python.exe c:\djtest\webinterface\ runserver localhost:8585. For some reason I get an error that it does not find the template “registration/login.html” which is in c:\djtest\templates.
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ["templates"],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Template-loader postmortem

Django tried loading these templates, in this order:

Using engine django:

    django.template.loaders.filesystem.Loader: C:\Windows\system32\templates\registration\login.html (Source does not exist)
    django.template.loaders.app_directories.Loader: C:\Program Files\Miniconda2\envs\reverse_edi\lib\site-packages\django\contrib\admin\templates\registration\login.html (Source does not exist)
    django.template.loaders.app_directories.Loader: C:\Program Files\Miniconda2\envs\reverse_edi\lib\site-packages\django\contrib\auth\templates\registration\login.html (Source does not exis
it is curious (to me at least) as to why the filesystem loader looks at system32
Dec 01 2016 09:53
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
Dennis Decoene
Dec 01 2016 09:55
yes that did the trick. somehow I always seem to mess up the template path part of the django app.
Thank you enormously!!!! you just saved my day!!!
Dec 01 2016 09:56
I had troubles with this issue too.
Dennis Decoene
Dec 01 2016 09:58
that and static files give me headaches :D
Dec 01 2016 10:00
and maybe that’s why it is strongly recommended not to use static files feature in production
Pami Ketolainen
Dec 01 2016 10:11
@IrSent who recommends that?
and what would be the alternative for the static files feature?
dedicated server or cdn
Pami Ketolainen
Dec 01 2016 10:20
well, yes, obviously not serving the static files via django, but using the static files feature is not in anyway not recommended
Dennis Decoene
Dec 01 2016 10:22
no I don’t use it in production but for testing/dev. Yet it always give me troubles getting it running.
Pami Ketolainen
Dec 01 2016 10:24
I would say that the point of the static files feature is to make it easy to both deploy them properly in production and use them in development with runserver
Simon Frid
Dec 01 2016 17:46
does anyone have good practices for importing settings from apps into a main project
in particular, configuring settings in a particular order. So that settings from kwargs > main project > default settings for app
Dec 01 2016 18:59
why you would even want to do something like that?
Dec 01 2016 19:53
подскажите, django выдает ошибку : File "/usr/lib/python2.7/importlib/", line 37, in import_module
File "/home/alex/seven/src/seven/", line 22, in <module>
url(r'^$', profiles.views.home, name = 'home'),
NameError: name 'profiles' is not defined

from . import profiles
не работает
from django.conf.urls import url, include
from django.contrib import admin
from . import profiles

urlpatterns =[
url(r'^$', profiles.views.home, name = 'home'),
вот мой

Philip Eckert
Dec 01 2016 20:36
So I'm working on a project a friend started, and he didn't implement the database when he should have.
I need to save model instances, to be later identified by their username. My code is as follows:
username = User.get_username()
        hydroInstance = HydroGraph(name=username, static_Pressure=statp, residual_Pressure=resP, supply_Flow=resFlow, 
            required_Pressure=reqP, required_Flow=reqFlow, elevation=elev, safety_Factor=safe, hose_Requirement=hose, 
I thought this was the proper way to save to the database, but when I check under the model in the admin page, I don't see any new models saved. Am I doing something wrong?
Simon Frid
Dec 01 2016 21:04
@IrSent because i'm trying to support a standalone app as well as an extension
Jimmy Merrild Krag
Dec 01 2016 21:17
@pae4557 Why doesn't HydroGraph use a foreign key to the user instead? Or am I misunderstanding something? Isn't User supposed to be a user instance?
Philip Eckert
Dec 01 2016 21:32
@beruic hmm you're right
@beruic username = request.user.get_username()
using that instead, it still gives me a value error that the pk doesn't exist, but I thought the pk was supposed to be there automatically, and only be removed if you specifically override that in the model?
@beruic Like .save() just does an INSERT instead of UPDATE so I forced it, and it just tells me that the PK doesn't exist :/