django-views

different nltk results in django and at command line

故事扮演 提交于 2020-01-06 17:10:51
问题 I have a django 1.8 view that looks like this: def sourcedoc_parse(request, sourcedoc_id): sourcedoc = Sourcedoc.objects.get(pk=sourcedoc_id) nltk.data.path.append('/root/nltk_data') new_words = [] english_vocab = set(w.lower() for w in nltk.corpus.gutenberg.words()) #<---the line where the error occurs results = {} template = 'sourcedoc_parse.html' params = {'sourcedoc': sourcedoc,'results': results, 'new_words': new_words, 'BASE_URL': BASE_URL} return render_to_response(template, params,

different nltk results in django and at command line

血红的双手。 提交于 2020-01-06 17:10:06
问题 I have a django 1.8 view that looks like this: def sourcedoc_parse(request, sourcedoc_id): sourcedoc = Sourcedoc.objects.get(pk=sourcedoc_id) nltk.data.path.append('/root/nltk_data') new_words = [] english_vocab = set(w.lower() for w in nltk.corpus.gutenberg.words()) #<---the line where the error occurs results = {} template = 'sourcedoc_parse.html' params = {'sourcedoc': sourcedoc,'results': results, 'new_words': new_words, 'BASE_URL': BASE_URL} return render_to_response(template, params,

multiple pagination in django class based view

笑着哭i 提交于 2020-01-06 15:24:51
问题 The code below paginates the queryset but how can I paginate context['guser1'] class AuthorList(ListView): template_name = 'authorList.html' paginate_by = 10 queryset = Author.objects.order_by('date') def get_context_data(self, **kwargs): context = super(AuthorList, self).get_context_data(**kwargs) if int(self.kwargs['user_id']) != self.request.user.id: raise PermissionDenied if self.request.user.username == 'guest': raise PermissionDenied context['guser1'] = Author.objects.order_by('date')

How to concept a web application (dashboard) made of Django in terms of backend structure

别等时光非礼了梦想. 提交于 2020-01-06 15:22:11
问题 My goal is to build a python/django based dashboard related to soccer where the user can select a soccer team of his choice in the sidebar and then gets all related data displayed in the dashboard in return. The dashboard will mostly consist of simple figures and more dynamic charts (using Plotly etc.). I attached the html frontend so you can get a brief feeling of how it will look like. As for the backend, I am not quiet sure what might be a good or even the best solution structurewise. I

Django, create multiselect checkbox input

我的未来我决定 提交于 2020-01-06 15:18:14
问题 I have a model with an integer field and would like to have an alternative form input render other than the default textbox, so that I have the following: models.py: myfield = models.IntegerField(default=7, blank=True) Would like to have the following: [x] Choice A (value 0) [ ] Choice B (value 1) [x] Choice C (value 2) So that upon save the choices would be calculated like the the following: (since choice A and C are selected and 2 is not selected). myfield = sum(choice selected multiplied

How to pass currently logged in user to filter.py i.e request based Filtering in django

自古美人都是妖i 提交于 2020-01-06 14:19:37
问题 I want to restrict the views for each user i.e a user can view only those account details that are related to him only. For this i have created a Filter where i want to pass the Logged in User details. Below is the snapshot of filter.py class networkFilterUserbased(django_filters.FilterSet): def __init__(self, *args, **kwargs): super().__init__(*args,**kwargs) request = kwargs['request'] username = request.user.id my_choices = NetworkRelatedInformation.objects.values_list('account', 'account_

Doing User Profiles In Django

徘徊边缘 提交于 2020-01-06 10:52:31
问题 I'm trying to set up user profiles in my site so we have: www.example.com/someuser www.example.com/anotheruser2 in my urls.py url(r'^(?P<profile>[0-9A-Fa-f]{1,36})/', 'site.views.profile), and my view: def profile(request, profile): ... do something ... There are two questions: Is this the correct way to do this or is there a better way? How should I handle other urls, like "aboutus", etc. For Point 2, I would do: url(r'^aboutus/', 'site.views.aboutus'), url(r'^(?P<profile>[0-9A-Fa-f]{1,36})/

Reverse for 'todo-user' with arguments '('',)' not found. 1 pattern(s) tried

我们两清 提交于 2020-01-06 08:43:12
问题 I am trying to add an user when clicking on a link but I have the following error : Reverse for 'todo-user' with arguments '('',)' not found. 1 pattern(s) tried: ['todo/(?P[^/]+)/$'] My views.py def todo_user(request, todo_id): todo.username.add(request.user) todo.save() return render(request, '/') Template <a href="{% url 'todo-user' todo.id %}"></a> Urls.py path('validate/<todo_id>/', views.todo_user, name='todo-user), Views.py for the template render : def home(request, token): todo

How to change the display of Django admin when use ManyToManyField

折月煮酒 提交于 2020-01-06 08:33:14
问题 I'm coding a news website.News model has a ManyToManyField foreign key named tag . Here is my News model: class News(models.Model): title = models.CharField(max_length=100, verbose_name='title') category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="cate", blank=True, verbose_name='Category') tag = models.ManyToManyField(Tag, blank=True, verbose_name='Tags') class Meta: verbose_name = "新闻" verbose_name_plural = verbose_name def __str__(self): return self.title Here is

Django: return the response to view function

青春壹個敷衍的年華 提交于 2020-01-06 07:59:07
问题 I have html checkout from that returns success/failure response. I want to pass this response back to view function. <html> <body> <button id="rzp-button">Authenticate</button> <script src="https://checkout.razorpay.com/v1/checkout.js"></script> <script> var options = { "key": "test_key", "subscription_id": "{{ sub_id }}", "name": "My Billing Label", "description": "Auth txn for sub_8seKGNhVEOwnjj", "handler": function (response){ alert(response.razorpay_payment_id); } }; var rzp1 = new