Re: Webinterface for python script

2019-02-04 Thread Scot Hacker
Make a basic Django view. Place your script in a python module that lives 
inside your app. Call that module/ function from the Django view. See 
Django docs and tutorials on how to handle uploaded files. Pass the 
uploaded file to your module, and handle the return value(s) however you 
want. Hard to get more specific than that without seeing your code, but 
this should come together pretty quickly with some experimentation.

I never know what people mean by "Django is overkill for...". Django is 
lightweight and starts up very quickly, even with large/complex projects. 
Django saves you mountains of time compared to Flask, which makes you go 
shopping for every little piece of framework you need. Every time I've 
experimented with Flask, I've come running back to Django after realizing 
my time is too valuable to waste it on creating my own framework when a 
perfectly great one already exists. 

./s


On Sunday, February 3, 2019 at 7:53:20 AM UTC-8, Asad Hasan wrote:
>
> Hi All ,
>
>   I have created certain python scripts to analyze log files and 
> suggest solution based on logic which I invoke on the command line . I need 
> some information on how to execute these through browser . I am using :
>
> python test.py file1 file2 
>
> How do I use the browser to upload the files file1 and file2 and it 
> process the files .
>
> Please advice ,
>
> Thanks, 
>
>

-- 
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 post to this group, send email to django-users@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/88c2337b-7e8a-4e11-968f-30299b6229d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TemplateDoesNotExist at /vmail/inbox/

2019-02-04 Thread Alex Kimeu
It means the template you are trying to render is either not created or not
in the location where Django expects to be. Django does not see the
template you are trying to render.

On Tue, 5 Feb 2019, 04:28 senthu nithy  I am doing a project using Django. I got this error. I don't understand
> what this error really means.
> Thanks in advance!
> K.Senthuja
> Undergraduate Student (UOJ),
> https://www.linkedin.com/in/senthuja/
> https://medium.com/@senthujakarunanithy
>
> --
> 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 post to this group, send email to django-users@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/CALEaTU5PQaiOuekpgJS7B6gQkZeQEz-x8--RMmLvC9mjJDnFNw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@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/CACYP3VHVfVCm7LHqt7x6bNN78%2BwjXnVaC4YQEzaXxQygwz1HFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


A Django extension that implements PostgreSQL tables for partitioning and management based on dates.

2019-02-04 Thread monobiao
*Share a gadget:django-pg-timepart*

A Django extension that implements PostgreSQL tables for partitioning and 
management based on dates. It is suitable for partition management of giant 
tables with time columns like logging, messages or articles, periodically 
creating new partitions and archiving old partitions.
Documentationhttps://django-pg-timepart.readthedocs.io/en/latest/
*I hope to get some suggestions or corrections from everyone, thanks!*

-- 
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 post to this group, send email to django-users@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/f8abbe4e-b4f0-4f45-b2ba-6af17bfc7b89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Webinterface for python script

2019-02-04 Thread Derek
Django could be overkill for his.  Try using Flask e.g.

https://stackoverflow.com/questions/39321540/how-to-process-an-upload-file-in-flask

On Sunday, 3 February 2019 17:53:20 UTC+2, Asad Hasan wrote:
>
> Hi All ,
>
>   I have created certain python scripts to analyze log files and 
> suggest solution based on logic which I invoke on the command line . I need 
> some information on how to execute these through browser . I am using :
>
> python test.py file1 file2 
>
> How do I use the browser to upload the files file1 and file2 and it 
> process the files .
>
> Please advice ,
>
> Thanks, 
>
>

-- 
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 post to this group, send email to django-users@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/fff40aa3-f252-493e-a213-a416cd6d0f3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch at - Reverse with arguments '('',)' not found

2019-02-04 Thread B.navya spoorthi Sweety
hi all ,
i just started with django. i am following this document
https://docs.djangoproject.com/en/2.1/intro/tutorial01/
here database used is sqlite. but i want to try out  django+mongodb
what all changes i can made so that django uses mongodb database
where should i create database and use with django.

i knew Regular Mongo Db operations

but not able to do from Django


thanks in advance.
waiting for a reply

On Mon, Feb 4, 2019 at 5:18 PM Ivan Martić  wrote:

> Hi all,
>
> I need help.
> I keep getting this issue, NoReverseMatch at /
> Reverse for 'productsgrouping-update' with arguments '('',)' not found. 1
> pattern(s) tried: ['update/(?P[0-9]+)/$']
>
> not sure what am doing wrong. Any time I put url tag {% url
> 'productsgrouping-update' lista.id%} in html i get the error.
> Both url work as stand alone,* /index* and */index/update/1/* but when i
> put url tag all hell break loose.. I strugling for a week now. Thank you
> all in advance.
>
> **
> from django.shortcuts import render, redirect
> from django.http import HttpResponse
> from .models import Material4, MaterialGroup
> from django.db import connection
> from .forms import ProductgroupinputForm, MaterialGroupForm
> from django.conf import settings
>
> def productsView(request):
> lista = MaterialGroup.objects.all()
> #text5 = MaterialGroup.objects.get(id=url_id)
> #return redirect(reverse('productsgrouping_update', kwargs=('id':url_id)))
> return render(request, "productsgroup.html", {"lista" : lista})
>
> def productsUpdateView(request, url_id):
> text5 = MaterialGroup.objects.get(id=url_id)
> form5 = ProductgroupinputForm(request.POST or None, instance=text5)
>
> context1 = {'text5': text5,'form5': form5}
>
> if form5.is_valid():
> form5.save()
> return render(request, 'productsgroup-update.html', context1)
>
> **
> from django.urls import path
> from . import views
>
> urlpatterns = [
> path('', views.productsView, name='productsgrouping'),
> path('update//', views.productsUpdateView,
> name='productsgrouping-update'),
> ]
>
> **
> from django.contrib import admin
> from django.urls import path, include
> from django.contrib.staticfiles.urls import staticfiles_urlpatterns
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('', include('product.urls')),
> ]
>
>
> **
> from __future__ import unicode_literals
> from django.db import models, connection
> from django.utils import timezone
> from datetime import date
> from django.urls import reverse
>
> class Material4(models.Model):
> id = models.IntegerField(db_column='ID', primary_key=True,
> blank=False, unique=True)
> bukrs = models.CharField(db_column='BUKRS', max_length=3)
> materialid = models.CharField(db_column='MaterialID', max_length=50)
> maktx = models.CharField(db_column='MAKTX', max_length=150)
> input_group = models.IntegerField(db_column='Input_group')
>
> class Meta:
> managed = False
> db_table = 'Material4'
>
> def __str__(self):
> return '%s %s %s %s' % (self.id, self.materialid, self.maktx,
> self.input_group)
>
>
> **
> from django import forms
> from .models import Material4, MaterialGroup
>
> class ProductgroupinputForm(forms.ModelForm):
>
> class Meta:
> model = Material4
> fields = ['materialid', 'input_group', 'id', 'input_group']
>
> class MaterialGroupForm(forms.ModelForm):
>
> class Meta:
> model = MaterialGroup
> fields = ['material_group', 'id']
>
>
> --
> 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 post to this group, send email to django-users@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/0f15b6d9-4dec-4ef9-b79a-643fc37a8781%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@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/CAOdZuzz7K4WHEPKJtg38u%3DbEAeRagVQcOx82kqdmoWwmM0XEvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


get_expiry_age does not use expire_date column.

2019-02-04 Thread Shen Li
Hi community,

I find it strange that in the DB session backend, the get_expiry_age does 
not actually use the value from expire_data column in the model.

What is the indention of this design?

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 post to this group, send email to django-users@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/70061f6d-6048-431a-b73a-c782a4944758%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


mongoengine

2019-02-04 Thread B.navya spoorthi Sweety
hi all
 
i am trying django with mongo

i added following lines in settings.py

mongoengine.connect(
db="tools",
host="localhost"
)

i am seeing error 
  File "", line 697, in exec_module
  File "", line 222, in 
_call_with_frames_removed
  File "C:\c_burra_mongo_1\mysite\mysite\settings.py", line 124, in 
mongoengine.connect(
NameError: name 'mongoengine' is not defined

i am aware that i need to change something here
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

but not sure what to change

-- 
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 post to this group, send email to django-users@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/39ae38f8-c165-4c1d-af0c-4ad167065e40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: My django-admin startproject (project name) is not working

2019-02-04 Thread jake ksi
DID YOU CONFIGURE PYTHON ?

Sent from Mailspring 
(https://link.getmailspring.com/link/1549297886.local-887807ae-9dc1-v1.5.5-b7939...@getmailspring.com/0?redirect=https%3A%2F%2Fgetmailspring.com%2F=ZGphbmdvLXVzZXJzQGdvb2dsZWdyb3Vwcy5jb20%3D),
 the best free email app for work
On Feb 1 2019, at 2:34 am, C. Kirby  wrote:
> What is the specific error you get when you type the command? Are you 
> actually writing "(project name)"? That will not work - you are supposed to 
> replace "(project name)" with the actual name of a project as in: 
> django-admin startproject myproject
>
> On Thursday, January 31, 2019 at 6:24:16 AM UTC-5, Vkash Poudel wrote:
> > My django-admin startproject (project name) is not working
> >
> > I have tried alot and alot.But theres always a problem in the cmd
> >
>
> --
> 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 
> (https://link.getmailspring.com/link/1549297886.local-887807ae-9dc1-v1.5.5-b7939...@getmailspring.com/1?redirect=mailto%3Adjango-users%2Bunsubscribe%40googlegroups.com=ZGphbmdvLXVzZXJzQGdvb2dsZWdyb3Vwcy5jb20%3D).
> To post to this group, send email to django-users@googlegroups.com 
> (https://link.getmailspring.com/link/1549297886.local-887807ae-9dc1-v1.5.5-b7939...@getmailspring.com/2?redirect=mailto%3Adjango-users%40googlegroups.com=ZGphbmdvLXVzZXJzQGdvb2dsZWdyb3Vwcy5jb20%3D).
> Visit this group at https://groups.google.com/group/django-users 
> (https://link.getmailspring.com/link/1549297886.local-887807ae-9dc1-v1.5.5-b7939...@getmailspring.com/3?redirect=https%3A%2F%2Fgroups.google.com%2Fgroup%2Fdjango-users=ZGphbmdvLXVzZXJzQGdvb2dsZWdyb3Vwcy5jb20%3D).
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/174f1dbc-63de-4f2a-8946-46e195b92e27%40googlegroups.com
>  
> (https://link.getmailspring.com/link/1549297886.local-887807ae-9dc1-v1.5.5-b7939...@getmailspring.com/4?redirect=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fdjango-users%2F174f1dbc-63de-4f2a-8946-46e195b92e27%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter=ZGphbmdvLXVzZXJzQGdvb2dsZWdyb3Vwcy5jb20%3D).
> For more options, visit https://groups.google.com/d/optout 
> (https://link.getmailspring.com/link/1549297886.local-887807ae-9dc1-v1.5.5-b7939...@getmailspring.com/5?redirect=https%3A%2F%2Fgroups.google.com%2Fd%2Foptout=ZGphbmdvLXVzZXJzQGdvb2dsZWdyb3Vwcy5jb20%3D).
>

-- 
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 post to this group, send email to django-users@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/1549297886.local-887807ae-9dc1-v1.5.5-b7939d38%40getmailspring.com.
For more options, visit https://groups.google.com/d/optout.


Re: django kwargs are not passed with the view to html template

2019-02-04 Thread Mohammed Modhaffer
Thank you Karen,
Just now I realized that it was a typo which caused this pain. From now on,
I should type slowly.

Best regards!
Mohammed.

On Mon, Feb 4, 2019 at 6:02 PM Karen Tracey  wrote:

>
>> In the conference list html, this is the code snippent: `{{ conference.title }}`. It redirects to the conference
>> detail page without any problem. In the conference by country html, I have
>> the following code:
>>
>> 
>> {% for conferenc in conferences %}
>> > href="{% url 'conferences:conference-detail' pk=conference.pk
>> slug=conference.slug %}"> {{ conferenc.title }}  {%comment%} Here is
>> the problem. {% endcomment %}
>> {% endfor %}
>>  
>>
>
> This for loop has variable named conferenc but in the urtl tag the name
> conference is used. The same name needs to be used in both places. (If you
> change to conference note the use of conferenc to show the title will also
> need to change.
>
> (Thanks for all the detail in the question!)
>
> --
> 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 post to this group, send email to django-users@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/CACS9raciD2hFjbhuQjqBTTnydpQsNe_Ph3CmdehDzbXpvn2B5A%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@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/CAAbatOSZ0U_G-73VK9RmMhBpL4LfjzcgKfrkR9ZMLncmHRG%3Dkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: Admin form_url breakout problem

2019-02-04 Thread Matthew Pava
The flow looks fine.  And when you click refresh on your browser on step 4 does 
the page refresh properly?

Perhaps it's a caching issue.
Are you wrapping the billing_payment_view with admin_view()?
https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_urls
 --> scroll towards the bottom of that section


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mike Dewhirst
Sent: Sunday, February 3, 2019 1:42 AM
To: django-users@googlegroups.com
Subject: Re: Admin form_url breakout problem

Matthew

I was wrong. I'm still in trouble. I thought it might be an incomplete 
transaction so I tried making the the subscription.save() atomic but to 
no avail.

Here is what happens ...

1.  Add an ingredient which is payable

2.  Save mixture

3.  SubstanceAdmin.change_view() establishes ...

     subscription = None
     if ingredient.is_payable():
     get or create a subscription record and populate it with fee, 
gst etc.
     if the subscription.token field is blank (ie not paid):
     call billing_payment_view() which interfaces with Stripe 
via a js popup and
     a) gets a token in a hidden field
     b) calls Stripe.charge(token) and gets a json charge 
record back
                 c) populates the subscription.token field
     d) saves the subscription record
     e) creates a receipt record
     f) sends an email receipt
     g) puts thank you text and mixture url into context dict
     h) calls billing_success_view(request, context) to 
display success
    message including link back to mixture
     return super(SubstanceAdmin, self).change_view()

4.  On clicking the back-to-the-mixture link in success.html, the Admin 
brings
     up the Change Substance page without error but which is blank below the
     "Change Substance" heading. At that time the displayed URL in the 
address
     bar is exactly correct.

5.  If the dev server reloads the page will paint properly if refreshed.

Theory:

The subscription record has been saved but not in a way which is visible 
yet thereby confusing change_view() into thinking the token field is blank.

In other words the transaction needs to be committed 
pre-billing_success_view()

In testing this it sadly this makes no difference.

Mike


On 2/02/2019 6:06 pm, Mike Dewhirst wrote:
> I think I know. Don't waste time on this. I'll report back later.
>
> Mike
>
> On 2/02/2019 3:27 pm, Mike Dewhirst wrote:
>> I thought it was fixed but not so. It works perfectly *only* if the 
>> dev server reloads after all the work and prior to clicking the link 
>> on the success.html template back to the mixture (the substance with 
>> ingredients).
>>
>> I tried a workaround of making the link point to the substances list 
>> page first. No difference. All substance pages come up blank.
>>
>> When I reported earlier that it was working I must have changed some 
>> text in a view to improve the screen wording and on saving the dev 
>> server would have reloaded itself and that hid the problem.
>>
>> The admin url is correct  ...
>>
>> http://localhost:8000/admin/substance/substance/1442/change/
>>
>> ... but that refuses to display. There is no delay, no spinner. The 
>> server console window shows nothing.
>>
>> Not sure where to start looking.
>>
>> Maybe something has corrupted Django's in-memory list of url patterns?
>>
>> Is it caching?
>>
>> Thanks for any non-javascript hints
>>
>> Mike
>>
>> On 30/01/2019 5:13 pm, Mike Dewhirst wrote:
>>> Matthew
>>>
>>> I looked for preventDefault and found it in lots of javascript 
>>> scripts. So I decided instead to look at my python code which is 
>>> slightly easier for me to understand. I sort of refactored it and 
>>> cut large swags out to simplify and inserted lots of print 
>>> statements. Then I thought I'd better read your advice again and try 
>>> harder to understand it.
>>>
>>> The bit which made sense to me was ...
>>>
>>> 'let the admin handle it from there'
>>>
>>> ... I noticed that I was returning the billing payment_view. As soon 
>>> as I removed that 'return' and let the change_view return the super 
>>> call it started working.
>>>
>>> Thank you very much for persisting with me.
>>>
>>> The Admin is fabulous! Nobel prize for something is warranted :)
>>>
>>> Much appreciated
>>>
>>> Mike
>>>
>>> On 29/01/2019 2:31 am, Matthew Pava wrote:
 Hi Mike,
 When Stripe processes the payment, you need to preventDefault on 
 the form submit, then add the token from Stripe to a hidden input 
 in your form without affecting any other data in the form.  Then 
 you can do form.submit() and let the admin handle it from there.  
 Check out the Stripe documentation for some good examples.  I've 
 used it myself.

 -Original Message-
 From: django-users@googlegroups.com 

Re: Django timezone problem

2019-02-04 Thread Mikko Meronen
Hi,

Thank you for your answer. I tried timezone.now without parentheses, but it
gave me server error. I have also tried datetime, but I face the same issue.

The issue I have:
I want people to see what happened today in the past. So I created a
database where is a story or stories what happened in the history on this
day(date). My view should be able to pick a right story from the database
based on the users timezone. If Australian visits my webpage at this
moment, he should be able to see what happened on February 5 in the past
(it's already February 5 there). However he sees what happened on February
4, because it is February 4 here (in Finland or England, not sure what
timezone I'm using). So I want to make my view to understand the end user's
local time, so it can pick the right story from the database for the
webpage visitor.

-Mikko

ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users (
django-users@googlegroups.com) kirjoitti:

> Hello Mikko,
>
> There are basically two ways which I know . One is the timezone module
> that you are using another is datetime module. I believe that timezone
> module is more effective one.
> But instead of calling timezone.now() , call timezone.now.
>
> Or what is the exact issue are you facing?
>
> Regards,
> Amitesh Sahay
> *91-750 797 8619*
>
>
> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen <
> mikkovillemero...@gmail.com> wrote:
>
>
> Hi,
>
> Is there any easy way in Django to catch end user's local time when end
> user access the webpage?
>
> I have read django documentation and tried to google solutions, but I get
> quite confused. Below you will find my code. In short the code should show
> a story on my webpage what happened in the past on the current day. However
> it doesn't take into account the endusers local time, and thus doesn't work
> properly.
>
>
> *Views.py*
> from django.utils import timezone
>
> t = timezone.now() *[This should somehow react to endusers local
> time]*
> dm = t.strftime('%m-%d')
> history = history.objects.filter(monthday__exact=dm)
> historystory = random.sample(list(history), 1)
> args = {'historystory':historystory}
> return render(request, "news/home.html", args)
>
> *home.html*
> [in html I have just the basic things to show the content]
>
> 
> 
> {% for x in historystory %}
>  {{ x.title }} 
>  {{ x.subtitle }} 
>  {{ x.content }} 
> {% endfor %}
> 
> 
>
>
> *Settings.py*
> LANGUAGE_CODE = 'en-us'
> TIME_ZONE = 'UTC'
> USE_I18N = True
> USE_L10N = True
> USE_TZ = True
>
> You can check my webpage (http://www.topithenewsdoggy.com/) to get better
> understanding what I'm doing. The part is under Additional info.
>
> -Mikko
>
> --
> 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 post to this group, send email to django-users@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/CAGD0jj%2Bh_1Pd50eE0e0zXt8P-yozqCnZeYYXTe6bj6Tt6UopxA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 post to this group, send email to django-users@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/383150814.2310524.1549268121893%40mail.yahoo.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@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/CAGD0jjLXV%2BxwMtjE3BSd8aAiVPuePJXLV%2BKaTQZr%2B-78udz4fQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Passing pk arguments from a URL into another view

2019-02-04 Thread Gavin Boyle
Hi Pooya,

Once I’ve done the include, how can I then pass that PK into the view of
the included urls?

Thanks
Gavin

On Mon, 4 Feb 2019 at 08:15, Ivan Martić  wrote:

> Can you elaborate a bit, i have the same issue with noreverse error
>
> ned, 3. velj 2019. u 15:08 poOya mOsaddegh 
> napisao je:
>
>> Hi
>> You may use include in urls.py
>>
>> urlpatterns = [
>> path('', views.club_home, name='club_home'),
>> path('/', include(club_home_urls, namespace='club_home')),
>> ]
>>
>>
>>
>> On Sat, Feb 2, 2019 at 8:20 PM GavinB841 
>> wrote:
>>
>>> *Hi all,*
>>>
>>> *I am having issues using arguments from a URL in another view, I have
>>> reached out on stackover flow with no success, i believe i am wording this
>>> question poorly.*
>>>
>>> *To quickly explain *
>>>
>>>- *I have a main site which shows a list of sports clubs. When the
>>>user selects on one it renders that specific club home page using the PK
>>>passed in the template.*
>>>- *Once I get to this home page
>>>e.g. http://127.0.0.1:8000/club_home/2/
>>>  .  I have many sub-pages which a 
>>> user
>>>can select but I have no idea how I can use that same PK to filter data 
>>> in
>>>the other pages to only show details based on that club.*
>>>- *I would also like to include that PK in the rest of the URLs.
>>>e.g. http://127.0.0.1:8000/club_home/2/teams/
>>>*
>>>
>>>
>>> *Code:*
>>>
>>> *index.html:*
>>>
>>> Our Clubs
>>> {% for club in all_clubs %}
>>> 
>>> {{ club.club_name }}
>>> 
>>>   {% endfor %}
>>>
>>>
>>> *urls.py*
>>>
>>> I understand I must include the / before teams in the URL
>>> but I am unsure how to pass in that argument
>>>
>>> urlpatterns = [
>>> path('', views.club_home, name='club_home'),
>>> path('/', views.club_home, name='club_home_with_pk'),
>>> path('teams/', views.TeamInfo.as_view(), name='teams'),
>>> ]
>>>
>>>
>>>
>>>
>>>
>>> *views.py *
>>>
>>>
>>>
>>> def club_home(request, pk=None):
>>> if pk:
>>> club = ClubInfo.objects.filter(pk=pk)
>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>> elif request.user.is_authenticated:
>>> club = ClubInfo.objects.filter(user=request.user)
>>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>>> # photo = model.club_logo.ImageField(storage=profile_pics)
>>> args = {'club': club,
>>> 'club_posts': club_posts
>>> }
>>> return render(request, 'club_home_page.html', args)
>>>
>>>
>>>
>>> class TeamInfo(APIView):
>>> renderer_classes = [TemplateHTMLRenderer]
>>> template_name = 'teams.html'
>>>
>>> def get(self, request):
>>> serializer = TeamSerializer()
>>> user = ClubInfo.objects.filter(user=request.user).first()
>>> teams = Team.objects.filter(club_id=user.pk)
>>> return Response({'serializer': serializer,
>>>  'teams': teams,
>>>  })
>>>
>>>
>>>
>>> *club_main_page.html*
>>>
>>>
>>> navbar on club home page to get to other pages, I know I need to 
>>> include  into the **URL and** I need to pass this argument into the 
>>> href of this URL but as need to figure out the view before adding this 
>>>
>>>
>>>
>>> Team
>>>
>>>
>>>
>>> *Any idea what I need to add into the view to allow for this. I would 
>>> really appreciate any help as I've been stuck on this for weeks now. *
>>>
>>>
>>> *Thanks *
>>>
>>>
>>> *Gavin*
>>>
>>>
>>>
>>> *Séanadh Ríomhphoist/Email DisclaimerTá an ríomhphost seo agus aon
>>> chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus sin
>>> amháin é. Is féidir tuilleadh a léamh anseo.
>>> 
>>> This e-mail and any
>>> files transmitted with it are confidential and are intended solely for use
>>> by the addressee. Read more here.
>>>  *
>>>
>>> --
>>> 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 post to this group, send email to django-users@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/3465a2fc-347a-4096-b037-83be9b57d8a2%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails 

Re: django kwargs are not passed with the view to html template

2019-02-04 Thread Karen Tracey
>
>
> In the conference list html, this is the code snippent: `{{ conference.title }}`. It redirects to the conference
> detail page without any problem. In the conference by country html, I have
> the following code:
>
> 
> {% for conferenc in conferences %}
>  href="{% url 'conferences:conference-detail' pk=conference.pk
> slug=conference.slug %}"> {{ conferenc.title }}  {%comment%} Here is
> the problem. {% endcomment %}
> {% endfor %}
>  
>

This for loop has variable named conferenc but in the urtl tag the name
conference is used. The same name needs to be used in both places. (If you
change to conference note the use of conferenc to show the title will also
need to change.

(Thanks for all the detail in the question!)

-- 
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 post to this group, send email to django-users@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/CACS9raciD2hFjbhuQjqBTTnydpQsNe_Ph3CmdehDzbXpvn2B5A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django kwargs are not passed with the view to html template

2019-02-04 Thread Mohammed Modhaffer
I searched for hours but I could not find a solution. I am trying to filter 
conferences by country. Conference detail url works fine when I click on it 
from the main conference list. When I filter by country, the list of 
conferences in a given country are shown. However, when I click on a 
conference, it breaks and shows `Reverse for 'conference-detail' with 
keyword arguments '{'pk': '', 'slug': ''}' not found. 1 pattern(s) tried: 
['conferences\\/details\\/(?P[0-9]+)\\/(?P[-a-zA-Z0-9_]+)\\/$']`. 
I cannot figure out the problem in my code. 

Model:
  
from cities_light.models import Country, City
class Conference(models.Model):
title = models.CharField(max_length=512, default='')
slug = models.SlugField(max_length=512)
country = models.ForeignKey(Country, on_delete=models.CASCADE)
city = models.ForeignKey(City, on_delete=models.CASCADE)

def __str__(self):
return self.title

def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Conference, self).save(*args, **kwargs)

def get_absolute_url(self):
return reverse('conferences:conference-detail', kwargs={'pk': 
self.pk, 'slug': self.slug})

urls.py:

 

path('', views.ConferenceListView.as_view(), name='conference-list'),
path('details///', 
views.ConferenceDetailView.as_view(), name='conference-detail'),
path('country-list', views.ConferenceCountryListView.as_view(),
 
name='conference-country-list'),
path('country///', 
views.ConferenceByCountryView.as_view(),
 
name='conferences-in-single-country'),

Views:

class ConferenceByCountryView(generic.ListView):
template_name = 'conferences/conferences_in_country_list.html'
context_object_name = 'conferences'

def get_queryset(self, *args, **kwargs):
country = Country.objects.get(pk=self.kwargs.get('pk', None))
return Conference.objects.filter(country=country)

def get_context_data(self, **kwargs):
context = super(ConferenceByCountryView, 
self).get_context_data(**kwargs)
country = Country.objects.get(pk=self.kwargs.get('pk', None))
context['country'] = country
context['title'] = 'Conferences in ' + ' country'
return context


class ConferenceDetailView(generic.DeleteView):
model = Conference
template_name = 'conferences/conference_detail.html'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = self.object.title
context['pk'] = self.object.pk
context['slug'] = self.object.slug
return context

In the conference list html, this is the code snippent: `{{ conference.title }}`. It redirects to the conference 
detail page without any problem. In the conference by country html, I have 
the following code: 


{% for conferenc in conferences %}
 {{ conferenc.title }}  {%comment%} Here is 
the problem. {% endcomment %}
{% endfor %} 
 

When I click on the url, it raises the following error: 

Reverse for 'conference-detail' with keyword arguments '{'pk': '', 
'slug': ''}' not found. 1 pattern(s) tried: 
['conferences\\/details\\/(?P[0-9]+)\\/(?P[-a-zA-Z0-9_]+)\\/$']

Your kind help is highly appreciated. 

-- 
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 post to this group, send email to django-users@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/01419589-cba7-44ed-99ed-9fcc2708f2fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


NoReverseMatch at - Reverse with arguments '('',)' not found

2019-02-04 Thread Ivan Martić
Hi all,

I need help.
I keep getting this issue, NoReverseMatch at /
Reverse for 'productsgrouping-update' with arguments '('',)' not found. 1 
pattern(s) tried: ['update/(?P[0-9]+)/$']

not sure what am doing wrong. Any time I put url tag {% url 
'productsgrouping-update' lista.id%} in html i get the error.
Both url work as stand alone,* /index* and */index/update/1/* but when i 
put url tag all hell break loose.. I strugling for a week now. Thank you 
all in advance.

**
from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import Material4, MaterialGroup
from django.db import connection
from .forms import ProductgroupinputForm, MaterialGroupForm
from django.conf import settings

def productsView(request):
lista = MaterialGroup.objects.all() 
#text5 = MaterialGroup.objects.get(id=url_id)
#return redirect(reverse('productsgrouping_update', kwargs=('id':url_id)))
return render(request, "productsgroup.html", {"lista" : lista})

def productsUpdateView(request, url_id):
text5 = MaterialGroup.objects.get(id=url_id)
form5 = ProductgroupinputForm(request.POST or None, instance=text5)

context1 = {'text5': text5,'form5': form5}

if form5.is_valid():
form5.save()
return render(request, 'productsgroup-update.html', context1)

**
from django.urls import path
from . import views

urlpatterns = [
path('', views.productsView, name='productsgrouping'),
path('update//', views.productsUpdateView, 
name='productsgrouping-update'),
]

**
from django.contrib import admin
from django.urls import path, include
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('product.urls')),
]


**
from __future__ import unicode_literals
from django.db import models, connection
from django.utils import timezone
from datetime import date
from django.urls import reverse

class Material4(models.Model):
id = models.IntegerField(db_column='ID', primary_key=True, blank=False, 
unique=True)
bukrs = models.CharField(db_column='BUKRS', max_length=3)
materialid = models.CharField(db_column='MaterialID', max_length=50)
maktx = models.CharField(db_column='MAKTX', max_length=150)
input_group = models.IntegerField(db_column='Input_group')

class Meta:
managed = False
db_table = 'Material4'

def __str__(self):
return '%s %s %s %s' % (self.id, self.materialid, self.maktx, 
self.input_group)


**
from django import forms
from .models import Material4, MaterialGroup

class ProductgroupinputForm(forms.ModelForm):

class Meta:
model = Material4
fields = ['materialid', 'input_group', 'id', 'input_group']

class MaterialGroupForm(forms.ModelForm):

class Meta:
model = MaterialGroup
fields = ['material_group', 'id']


-- 
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 post to this group, send email to django-users@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/0f15b6d9-4dec-4ef9-b79a-643fc37a8781%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Passing pk arguments from a URL into another view

2019-02-04 Thread Ivan Martić
Can you elaborate a bit, i have the same issue with noreverse error

ned, 3. velj 2019. u 15:08 poOya mOsaddegh 
napisao je:

> Hi
> You may use include in urls.py
>
> urlpatterns = [
> path('', views.club_home, name='club_home'),
> path('/', include(club_home_urls, namespace='club_home')),
> ]
>
>
>
> On Sat, Feb 2, 2019 at 8:20 PM GavinB841  wrote:
>
>> *Hi all,*
>>
>> *I am having issues using arguments from a URL in another view, I have
>> reached out on stackover flow with no success, i believe i am wording this
>> question poorly.*
>>
>> *To quickly explain *
>>
>>- *I have a main site which shows a list of sports clubs. When the
>>user selects on one it renders that specific club home page using the PK
>>passed in the template.*
>>- *Once I get to this home page
>>e.g. http://127.0.0.1:8000/club_home/2/
>>  .  I have many sub-pages which a 
>> user
>>can select but I have no idea how I can use that same PK to filter data in
>>the other pages to only show details based on that club.*
>>- *I would also like to include that PK in the rest of the URLs.
>>e.g. http://127.0.0.1:8000/club_home/2/teams/
>>*
>>
>>
>> *Code:*
>>
>> *index.html:*
>>
>> Our Clubs
>> {% for club in all_clubs %}
>> 
>> {{ club.club_name }}
>> 
>>   {% endfor %}
>>
>>
>> *urls.py*
>>
>> I understand I must include the / before teams in the URL but
>> I am unsure how to pass in that argument
>>
>> urlpatterns = [
>> path('', views.club_home, name='club_home'),
>> path('/', views.club_home, name='club_home_with_pk'),
>> path('teams/', views.TeamInfo.as_view(), name='teams'),
>> ]
>>
>>
>>
>>
>>
>> *views.py *
>>
>>
>>
>> def club_home(request, pk=None):
>> if pk:
>> club = ClubInfo.objects.filter(pk=pk)
>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>> elif request.user.is_authenticated:
>> club = ClubInfo.objects.filter(user=request.user)
>> club_posts = ClubPosts.objects.filter(club_id=club[0])
>> # photo = model.club_logo.ImageField(storage=profile_pics)
>> args = {'club': club,
>> 'club_posts': club_posts
>> }
>> return render(request, 'club_home_page.html', args)
>>
>>
>>
>> class TeamInfo(APIView):
>> renderer_classes = [TemplateHTMLRenderer]
>> template_name = 'teams.html'
>>
>> def get(self, request):
>> serializer = TeamSerializer()
>> user = ClubInfo.objects.filter(user=request.user).first()
>> teams = Team.objects.filter(club_id=user.pk)
>> return Response({'serializer': serializer,
>>  'teams': teams,
>>  })
>>
>>
>>
>> *club_main_page.html*
>>
>>
>> navbar on club home page to get to other pages, I know I need to include 
>>  into the **URL and** I need to pass this argument into the href of this 
>> URL but as need to figure out the view before adding this 
>>
>>
>>
>> Team
>>
>>
>>
>> *Any idea what I need to add into the view to allow for this. I would really 
>> appreciate any help as I've been stuck on this for weeks now. *
>>
>>
>> *Thanks *
>>
>>
>> *Gavin*
>>
>>
>>
>> *Séanadh Ríomhphoist/Email DisclaimerTá an ríomhphost seo agus aon
>> chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus sin
>> amháin é. Is féidir tuilleadh a léamh anseo.
>> 
>> This e-mail and any
>> files transmitted with it are confidential and are intended solely for use
>> by the addressee. Read more here.
>>  *
>>
>> --
>> 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 post to this group, send email to django-users@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/3465a2fc-347a-4096-b037-83be9b57d8a2%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> 

Re: Django timezone problem

2019-02-04 Thread 'Amitesh Sahay' via Django users
Hello Mikko,
There are basically two ways which I know . One is the timezone module that you 
are using another is datetime module. I believe that timezone module is more 
effective one.But instead of calling timezone.now() , call timezone.now.
Or what is the exact issue are you facing?


Regards,
Amitesh Sahay91-750 797 8619 

On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen 
 wrote:  
 
 Hi,
Is there any easy way in Django to catch end user's local time when end user 
access the webpage?
I have read django documentation and tried to google solutions, but I get quite 
confused. Below you will find my code. In short the code should show a story on 
my webpage what happened in the past on the current day. However it doesn't 
take into account the endusers local time, and thus doesn't work properly.

Views.pyfrom django.utils import timezone

t = timezone.now()     [This should somehow react to endusers local time]dm = 
t.strftime('%m-%d')history = 
history.objects.filter(monthday__exact=dm)historystory = 
random.sample(list(history), 1)args = {'historystory':historystory}return 
render(request, "news/home.html", args)

home.html[in html I have just the basic things to show the content]
                            {% for x 
in historystory %}      {{ x.title }}           {{ x.subtitle }}       {{ 
x.content }}      {% endfor %}         

Settings.pyLANGUAGE_CODE = 'en-us'TIME_ZONE = 'UTC'USE_I18N = TrueUSE_L10N = 
TrueUSE_TZ = True
You can check my webpage (http://www.topithenewsdoggy.com/) to get better 
understanding what I'm doing. The part is under Additional info.
-Mikko

-- 
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 post to this group, send email to django-users@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/CAGD0jj%2Bh_1Pd50eE0e0zXt8P-yozqCnZeYYXTe6bj6Tt6UopxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
  

-- 
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 post to this group, send email to django-users@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/383150814.2310524.1549268121893%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.