Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 44

0
votes
answers
6 views
+10

Django的模板URL不叫Django的REST API

0

我有以下Django的REST API終點Django的模板URL不叫Django的REST API

url(r'^api/email-verification/(?P<pk>[0-9]+)/$', EmailVerificationApiView.as_view(), name="email-verified") 

和下面是我在哪裏應用此API來驗證用戶,即點擊之後下面Activate HTML模板鏈接,上面提到的API端點將被調用,並在後端用戶將flaged驗證,但與點擊的HTML按鈕,它不會調用API。

<body> 
      <tr> 
      <td class="button"> 
       <div><!--[if mso]> 
       <v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="http://" style="height:45px;v-text-anchor:middle;width:155px;" arcsize="15%" strokecolor="#ffffff" fillcolor="#ff6f6f"> 
        <w:anchorlock/> 
        <center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center> 
       </v:roundrect> 
        <a href="{% url 'email-verified' user_id %}"> 
        Activate 
        </a> 
       </div> 
      </td> 
      </tr> 
<body> 

點擊Actvate按鈕後,它重定向我另一個頁面這給下面的語句

Redirect Notice 
     The page you were on is trying to send you to an invalid URL (http:///api/email-verification/103/). 

    If you do not want to visit that page, you can return to the previous page. 

。我是在Django相對較新,Django的休息api.Is有沒有其他特殊的方式來調用Django休息api在Django的模板url標籤?

在提,API是一個POST API和上面給出的HTML模板是一個電子郵件模板。

+0

我想這個答案可能會有所幫助:https://stackoverflow.com/questions/25345392/how-to-add -url-parameters-to-django-template-url-tag –

+0

我更新了我的問題。 – RTan

+0

什麼是''標籤 – Satendra

沙发
0
-1

在模板中你有

{% url 'email-verified' user_id %} 

它應該是:

{% url 'email-verified' pk=user_id %} 
+0

href =「http://」的目的我不工作,我也更新了我的問題。點擊Activate按鈕後,它會將我的網頁重定向到一個頁面,這表明我正嘗試在無效url中重定向,例如http:/// api/email-verification/103 /'。它實際上是從一開始就發生的,對不起,我最初沒有給它。 – RTan

+0

在http://''部分:'http:/// api/email-verification/103 /' –

+1

之後,您在url中獲得了一個額外的'/'另外,在閱讀包含事實上,你的api期待'post':你如何期待一個帶有''鏈接的帖子?要提交帖子,你需要一個表單。而且您無法從郵件正文中提交帖子。 –

0
votes
answers
32 views
+10

如果差異是正負2,則突出顯示單元格?

0

我有2列,列A和B,它們都預先填入數字。如果差異是正負2,則突出顯示單元格?

我想突出顯示差異數字爲+2或-2的行。如果(A1-B1> 2或A1-b1 < 2)=改變文字顏色。

我想在谷歌牀單條件格式設置。

誰能幫助?

感謝

+0

你是說如果差異大於+2或小於-2? –

沙发
0
2

如果你的意思是此差超過2無論哪種方式,最短的是

=abs($A1-$B1)>2 

爲自定義公式。

+0

就是這樣。謝謝! – teep

+0

很高興爲你效勞。 –

0
votes
answers
29 views
+10

復發T(n)= T(n - log(n))+ 1

0

你如何找到這樣的遞推關係的嚴格界限?這是一個重要的問題,我們期望證明m/log(m)是嚴格的漸近界。我嘗試使用感應,但它似乎無處可去。這是要麼我缺少對數規則或有更多的東西。復發T(n)= T(n - log(n))+ 1

+0

告訴我們你如何開始歸納,也許有人可以從那裏幫助你。 – ShadowMitia

沙发
0
1

感應。假設所有k < nT(k) <= C k/log k對於某些C

展開復發(n/2)/log(n/2)次,更換log(.)log(n/2)(我們利用的事實,即T(n)log(n)是單調函數)。也就是說,

T(n) <= T(n - log(n/2) * (n/2)/log(n/2)) + (n/2)/log(n/2)

T(n) <= T(n/2) + (n/2)/log(n/2)

T(n) <= C (n/2)/log(n/2) + (n/2)/log(n/2)

現在你要證明右邊的表達被C n/log n界。算術和找到這樣的C是作爲一個練習。

+0

我不同意。我認爲解決方案的形式應該是: '(n-log(n))/(log(n-log(n)))' – ugar

+0

@nomadov它取決於你需要的近似程度。 –

+0

如何展開次數?(n/2)/ log(n/2)次?我不明白你是如何得到T(n)<= T(n-log(n/2)*(n/2)/ log(n/2))+(n/2)/ log(n/2 )' – ugar

0
votes
answers
8 views
+10

無法理解一些Go代碼

2

,我發現像這樣的代碼:無法理解一些Go代碼

// first returns the first address which satisfies strategy, or if 
// none do, then the first address of any kind. 
func (addrs addrList) first(strategy func(Addr) bool) Addr { 
    for _, addr := range addrs { 
     if strategy(addr) { 
      return addr 
     } 
    } 
    return addrs[0] 
} 

我真搞不清楚爲什麼FUNC包括:第一另一FUNC命名FUNC (Addr),以及該代碼如何實現評論所說的行爲?

+0

func(Addr)bool是參數_strategy_的**類型**。所以參數「策略」必須是一個函數,它需要_Addr_類型的東西並返回true或false。 – 2017-11-18 08:40:31

+0

所以,我想確認的一件事是:func(Addr)bool是類似「string」還是「int」的?但這個func如何返回滿足策略的第一個地址? – user8645601

沙发
0
1

考慮戰略作爲過濾器的功能,它只檢查地址範圍內循環可通過過濾器或不 另一個完全平等的方式做,這是像

func strategy(addr Addr) bool { 
    if addr == ... { 
     return true 
    } 

    return false 
} 

func main(){ 
    addr := first(strategy) 
} 
板凳
0
2
1 func (addrs addrList) first(strategy func(Addr) bool) Addr { 
2 for _, addr := range addrs { 
3  if strategy(addr) { 
4   return addr 
     } 
    } 
5 return addrs[0] 
    } 

在關鍵詞:

  1. 功能上addrs名爲first回報Addr花費strategy參數必須是一個函數,它需要Addr並返回bool
  2. foraddrsrange每個addraddr
  3. 應用功能strategy如果它(strategy FUNC)返回true
  4. 然後整體功能first返回該addr
  5. 整體功能first返回第一個[0]Addraddrs,暗示:只有當strategy呼叫addr時纔會發生中的0返回true
地板
0
1

Func first接受作爲參數strategy另一種功能類型func(Addr) bool。 所以第二個函數應該以Addr作爲輸入並返回bool加法器是否正常。

作爲第一個這樣的Addr發現第一個函數退出並返回它。

登錄與過濾器類似 - 迭代列表直到找到第一個匹配值。

作爲最後的手段,如果沒有人Addr值得到肯定的答覆第一個函數返回片中的第一個值。

0
votes
answers
26 views
+10

Django runserver顯示HTTP

0

我配置了nginx來運行HTTPS。我還重寫了所有規則,以便它在HTTPS下運行。Django runserver顯示HTTP

但是,Django仍然在內部運行HTTP嗎?

Django version 1.2.1, using settings 'myproject.settings' 
Development server is running at http://127.0.0.1:8000/ 
Quit the server with CONTROL-C. 
[14/Aug/2012 23:57:04] "GET /app/c HTTP/1.0" 200 4 
[14/Aug/2012 23:57:09] "GET /app/c HTTP/1.0" 200 4 

是的。我知道我的版本已經過時了。

我檢查了request.is_secure,它在我訪問HTTPS時返回True。

+0

你怎麼不使用WSGI或至少FastCGI? – 2012-08-15 04:01:38

+0

@ IgnacioVazquez-Abrams嗯你是什麼意思?然而,我的確在運行gunicorn。 – User007 2012-08-15 04:09:58

沙发
0
1

正確,在內部您將使用http通過代理服務器進行通信,但所有外部通信都將使用https方法。

爲了進一步保護您的流量,請確保您只綁定到本地地址,或者使用套接字連接nginx和您的應用程序服務器。

我的確希望你不是在生產中使用django的開發服務器,而應該使用諸如gunicorn之類的東西作爲你的應用服務器。

+0

謝謝。的確,我確實使用gunicorn進行生產。只是一個簡短的問題,當你說綁定到一個本地地址,你在nginx conf中說我只綁定'http:// localhost:8000'?只要可能,我也只使用'$ host'變量。 – User007 2012-08-15 04:10:48

+0

僅綁定到您的應用程序服務器/ gunicorn的「本地主機」主機。對於你想綁定到你想要聽的所有地址的nginx。 – 2012-08-15 04:32:56

0
votes
answers
33 views
+10

Django模板中的不同模型

0

我在Django中很新,找不到解決方案。如何在1個模板中傳遞來自不同模型的2個查詢集?我使用mptt類別並與它一起堆疊一段時間。我知道我必須用views.py做些什麼,但我怎樣才能組合這些查詢集?這裏是我的Models.pyDjango模板中的不同模型

from __future__ import unicode_literals 
from django.db import models 
from django.core.urlresolvers import reverse 
from mptt.models import MPTTModel, TreeForeignKey 


class Variant(MPTTModel): 
category = models.CharField(max_length=500) 
logo = models.ImageField(upload_to='images/', null=True, blank=True) 
slug = models.SlugField(max_length=160, blank=True, null=True) 
parent = TreeForeignKey('self', null=True, blank=True, 
    related_name='children', db_index=True, 
         on_delete=models.CASCADE) 

class MPTTMeta: 
    order_insertion_by = ['category'] 

class Meta: 
    verbose_name = 'категория' 
    verbose_name_plural = 'категории' 

def get_absolute_url(self): 
    return reverse('cosmetics:details', kwargs={'pk': self.pk}) 

def __str__(self): 
    return self.category 

def is_second_node(self): 
     return True if (self.get_ancestors().count() == 1) else False 



class Pic_Discription(models.Model): 
variant = TreeForeignKey('Variant', null=True, blank=True) 
model = models.CharField(max_length=500) 
pic_title = models.ImageField(upload_to='images/', null=True, blank=True) 
description = models.TextField(default='') 
price = models.DecimalField(max_digits=10, decimal_places=2, default=0) 
slug = models.SlugField(max_length=160,blank=True, null=True) 
available = models.BooleanField(default=True) 

class Meta: 
    verbose_name = 'Продукт' 
    verbose_name_plural = 'Продукты' 

def __str__(self): 
    return self.model 

def get_absolute_url(self): 
    return reverse('cosmetics:details', kwargs={'pk': self.pk}) 

Views.py

class CategoryView(generic.ListView): 
model = Variant 
template_name = 'cosmetics/homepage.html' 

def get_context_data(self, *, object_list=None, **kwargs): 
    """Get the context for this view.""" 
    queryset = object_list if object_list is not None else self.object_list 
    page_size = self.get_paginate_by(queryset) 
    context_object_name = self.get_context_object_name(queryset) 
    if page_size: 
     paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size) 
     context = { 
      'paginator': paginator, 
      'page_obj': page, 
      'is_paginated': is_paginated, 
      'object_list': queryset 
     } 
    else: 
     context = { 
      'paginator': None, 
      'page_obj': None, 
      'is_paginated': False, 
      'object_list': queryset 
     } 
    if context_object_name is not None: 
     context[context_object_name] = queryset 
    context.update(kwargs) 
    context['nodes'] = context.get('object_list') 
    return super().get_context_data(**context) 

我也嘗試添加了模型的另一個類的看法,但它不工作

class ProductsView(generic.ListView): 
model = Pic_Discription 
template_name = 'cosmetics/homepage.html' 

def get_queryset(self): 
    return Pic_Discription.objects.all() 

我的網址:

urlpatterns = [ 
#/cosmetics/ 
url(r'^$', views.CategoryView.as_view(), name='homepage'), 
#/cosmetics/5/ 
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='details'), 

url(r'^products/$', views.ProductsView.as_view(), name='products'), 
] 

這裏是一個模板:

{% load mptt_tags %} 

{% block body %} 
    <div class="container-fluid2"> 
    <div class="col-md-2 col-sm-2"> 

     <div class="panel panel-default" id="categories"> 
     <div class="panel-header" id="cat-head">Категории</div> 
     <div class="panel-body" id="content-cat"> 
      {% recursetree nodes %} 
          <div class=" 
            {% if node.is_root_node %} 
            root 
            {% elif node.is_child_node and not 
            node.is_leaf_node or node.is_second_node%} 
            child 
            {% elif node.is_leaf_node and not 
            node.is_root_node%} 
            leaf 
            {%endif%}"> 
            {{node.category}} 
           </div> 
           {% if not node.is_leaf_node%} 
           <ul>{{children}}</ul> 
           {% endif %} 
       {% endrecursetree %} 
     </div> 
     </div> 
    </div> 



     {% for cosmetic in object_list %} 
      <div class="col-md-3 col-sm-4"> 
       <div class="thumbnail"> 
        <a href="{% url 'cosmetics:details' cosmetic.id %}"> 
         {% if cosmetic.pic_title %} 
          <img src="{{ cosmetic.pic_title.url }}" class="img-responsive"> 
         {% else %} 
          <h3>Изображение отсутствует</h3> 
         {% endif %} 
        </a> 
        <div class="caption" id="textyInfo"> 
         <h2>{{ cosmetic.model }}</h2> 
         <!-- View Details --> 
         <a href="{% url 'cosmetics:details' cosmetic.id %}" class="btn btn-primary btn-sm" role="button"> 
          Подробнее 
         </a> 
        </div> 
       </div> 
      </div> 
      {% cycle '' '' '' '' '' '<div class="clearfix visible-lg"></div>' %} 
     {% endfor %} 



</div> 
{% endblock %} 
沙发
0
0

只需使用情境:

from .models import MyModel 

... 
context['my_model'] = MyModel.objects.all() 
.... 

在你的模板,例如

{% for m in my_model %} 
    {% m.myfield %} 
{% enfor %} 
+0

我知道,但我怎麼能實現它在現有的views.py代碼? –

0
votes
answers
26 views
+10

配額在開發環境終點框架v2和部署項目

0

症狀配額在開發環境終點框架v2和部署項目

我開發服務器上工作,但在部署到GCP的響應是一個新的標準環境終點框架(V2)項目:應用程序暫時超過其服務配額。請稍後再試。

但是,如果我嘗試添加配額限制和指標(根據https://cloud.google.com/endpoints/docs/frameworks/quotas-configure),則開發服務器錯誤爲:AttributeError:'tuple'對象沒有屬性'metric_name'。

下面是完整的錯誤記錄。我懷疑有關oauth2client的警告與配額問題無關,但與當前的端點模塊有關。

該錯誤似乎指向limit_definitions,但這些來自Google示例。

代碼片段:

quota_limits = [ 
    ("read-requests", "Read Requests", 1000), 
    ("list-requests", "List Requests", 100), 
    ("write-requests", "Write Requests", 50), 
] 

@endpoints.api(
    name='echo', 
    version='v1', 
    limit_definitions=quota_limits, 

問:
如何,我不是:不使用配額或正確配置配額?還是有錯誤?顯示 gcloud信息

Google Cloud SDK [180.0.0] 

Platform: [Linux, x86_64] ('Linux', 'host-name', '4.4.0-98-generic', '#121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017', 'x86_64', 'x86_64') 
Python Version: [2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]] 
Python Location: [/usr/bin/python2] 
Site Packages: [Disabled] 

Installation Root: [/home/steve/google-cloud-sdk] 
Installed Components: 
    core: [2017.11.10] 
    app-engine-python: [1.9.63] 
    gcloud: [] 
    beta: [2017.09.15] 
    gsutil: [4.28] 
    cloud-datastore-emulator: [1.3.0] 
    bq: [2.0.27] 
System PATH: [/home/steve/google-cloud-sdk/bin:/home/steve/.nvm/versions/node/v6.11.1/bin:/home/steve/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/steve/google-cloud-sdk/platform/google_appengine:/home/steve/Android/Sdk/tools:/home/steve/Android/Sdk/tools/bin:/home/steve/Android/Sdk/platform-tools:~/bin:~/.config/yarn/global/node_modules/.bin] 
Python PATH: [/home/steve/google-cloud-sdk/lib/third_party:/home/steve/google-cloud-sdk/lib:/usr/lib/python2.7/:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload] 
Cloud SDK on PATH: [True] 
Kubectl on PATH: [False] 
There are alternate versions of the following Google Cloud Platform tools on your system PATH. 
    /home/steve/google-cloud-sdk/platform/google_appengine/dev_appserver.py 
    /home/steve/google-cloud-sdk/platform/google_appengine/endpointscfg.py 

Installation Properties: [/home/steve/google-cloud-sdk/properties] 
User Config Directory: [/home/steve/.config/gcloud] 
Active Configuration Name: [default] 
Active Configuration Path: [/home/steve/.config/gcloud/configurations/config_default] 

Account: [<removed-for-public-post>] 
Project: [project-name] 

Current Properties: 
    [core] 
    project: [project-name] 
    account: [<removed for public post>] 
    disable_usage_reporting: [False] 

Logs Directory: [/home/steve/.config/gcloud/logs] 
Last Log File: [/home/steve/.config/gcloud/logs/2017.11.18/11.00.31.517561.log] 

git: [git version 2.7.4] 
ssh: [OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016] 

完整的錯誤:

SDK

WARNING 2017-11-18 05:57:18,958 multistore_file.py:62] The oauth2client.contrib.multistore_file module has been deprecated and will be removed in the next release of oauth2client. Please migrate to multiprocess_file_storage. 
ERROR 2017-11-18 05:57:19,080 wsgi.py:263] 
Traceback (most recent call last): 
    File "/home/steve/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle 
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) 
    File "/home/steve/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler 
    handler, path, err = LoadObject(self._handler) 
    File "/home/steve/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject 
    obj = __import__(path[0]) 
    File "/home/steve/gae/prototyping/endpoint+fbauth/main.py", line 35, in <module> 
    'https://www.googleapis.com/service_accounts/v1/metadata/x509/[email protected]')} 
    File "/home/steve/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0/protorpc/util.py", line 173, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/home/steve/gae/prototyping/endpoint+fbauth/lib/endpoints/api_config.py", line 1038, in api 
    limit_definitions=limit_definitions) 
    File "/home/steve/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0/protorpc/util.py", line 173, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/home/steve/gae/prototyping/endpoint+fbauth/lib/endpoints/api_config.py", line 508, in __init__ 
    base_path=base_path, limit_definitions=limit_definitions) 
    File "/home/steve/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0/protorpc/util.py", line 173, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/home/steve/gae/prototyping/endpoint+fbauth/lib/endpoints/api_config.py", line 601, in __init__ 
    _CheckLimitDefinitions(limit_definitions) 
    File "/home/steve/gae/prototyping/endpoint+fbauth/lib/endpoints/api_config.py", line 243, in _CheckLimitDefinitions 
    if not ld.metric_name: 
AttributeError: 'tuple' object has no attribute 'metric_name' 
沙发
0
0

quota_limits需求是endpoints.api_config.LimitDefinition實例,而不是一個元組的列表清單。這是文檔中的錯誤;我會確保它們得到糾正,並且我會改進錯誤信息以便更清楚。

0
votes
answers
12 views
+10

成分不創建外鍵引用

0

我有兩個域類如下,成分不創建外鍵引用

class Agent { 
    String name 
    Team team 
} 

class Team { 
    String name 
    Agent primarySupervisor 
    static hasMany = [secondarySupervisors:Agent] 
} 

每劑具有團隊,每個團隊都有一個主監控器和多個次級監事。

上面代碼中不產生二次監事映射表,如果我從代理域或primarySupervisor從域刪除團隊屬性,則它會創建映射表。

我在做什麼錯?

沙发
0
0

此域類結構應該適合您。

class Agent { 
     String name 
     static belongsTo = Team 
     static hasOne = [team: Team] // Every agent has a team 
    } 

    class Team { 
     String name 
     static hasMany = [secondarySupervisors:Agent] // every team has a primary supervisor and multiple secondary supervisors 
    } 

這裏有很多的關係將形成一個新的表作爲team_agent

10
votes
answers
20 views
+10

Multiple pagination (ajax) not working for django-el-pagination

I have 2 querysets: Post and Comment. I'm using django-el-pagination to render these using ajax.

Here's my view:

def profile(request, user, extra_context=None):

    profile = Profile.objects.get(user__username=user)

    page_template = 'profile.html'

    if request.is_ajax():
        user_queryset = request.GET.get('user_queryset')
        print('Queryset:', user_queryset)
        if user_queryset == 'user_posts':
            page_template = 'user_posts.html'
        elif user_queryset == 'user_comments':
            page_template = 'user_comments.html'
        else:
            pass

    print('Template:', page_template)

    user_posts = Post.objects.filter(user=profile.user).order_by('-date')
    user_comments = Comment.objects.filter(user=profile.user).order_by('-timestamp')

    context = {'user_posts': user_posts,'user_comments': user_comments, 'page_template': page_template}

    if extra_context is not None:
        context.update(extra_context)

    return render(request, page_template, context)

I have an ajax call that find out which query set is being used. So when 'more comments' or 'more posts' (in the template) is being clicked to get more paginated objects, I know which queryset it's from. However when I use the above code and click 'more' for the ajax pagination, it appends the whole page, not the relevant child template (user_posts.html or user_comments.html). But the if request.is_ajax() code block works fine; it prints the correct template to use so this shouldn't be happening.

When I change that code block to this

if request.is_ajax():
    page_template = 'user_posts.html'

The ajax pagination for Post works. However I'd like to add ajax pagination for Comment aswell. Why doesn't my initial if request.is_ajax() work and how can I fix it?

EDIT:

Output of when I click on on more posts:

Queryset: None
Template: profile.html
Queryset: user_posts
Template: user_posts.html

js

$('body').on('click', '.endless_more', function() {
    console.log($(this).html()); #works successfully 
    var user_queryset;
    if ($(this).html() === 'more posts') {
        console.log('POSTS'); #works successfully 
        var user_queryset = 'user_posts'
    } else if ($(this).html() === 'more user comments') {
        user_queryset = 'user_comments';
        console.log('COMMENTS'); #works successfully 
    } else {
        console.log('none');
    }
    $.ajax({
        type: 'GET',
        url: window.location.href,
        data: {
            'user_queryset': user_queryset
        }

    })
});

profile.html

<!--posts-->
<div class="user_posts_div">
    <div class="endless_page_template">
        {% include "user_posts.html" %}
    </div>
</div>

<!--comments-->
<div class="user_comments_div">
    <div class="endless_page_template">
        {% include "user_comments.html" %}
    </div>
</div>

user_posts.html (child template)

{% paginate 5 user_posts %}
    {% for post in user_posts %}
        <div class="user_post">
            <p class="user_post_title_p"><a class="user_post_title" href="{% url 'article' category=post.entered_category id=post.id %}">{{ post.title }}</a></p>
            <p class="user_post_category">/{{ post.entered_category }}</p>
            <p class="user_post_date">{{ post.date|timesince }}</p>
        </div>

    {% endfor %}
{% show_more 'more posts' '...' %}
沙发
+90

以下行的輸出是什麼?

  print('Queryset:',user_queryset)  

我認為你在下面的行有問題< / p>

  user_queryset = request.GET.get('user_queryset')  

這不會返回正確的get參數值,以匹配post和comment部分的條件。

我已經在編輯中添加了我的模板,你能看一下嗎?是的,我有點理解你在說什麼,但如果不使用js,我還能如何允許超過1個查詢集(帖子,評論等)?我試圖複製這個,但我認為我的觀點錯了:django-el-pagination.readthedocs.io/en/latest/ - Zorgan 7月24日在10:13

板凳
+10

您可以查看附近的javascript:

  user_queryset ='user_comments';   

嘗試將其更改為:

  var user_queryset ='user_comments';   

我假設,如果你直接去評論,那麼變量user_queryset將是未定義的,並且它不會作為'user_comments'傳遞。

是的,我已經嘗試過,並沒有修復任何問題。我剛剛編輯了我的JS,它顯示我之前聲明了user_queryset變量,所以它沒有未定義。JS發送正確的數據,問題似乎在視圖中。 - Zorgan於17年8月8日在12:31

0
votes
answers
28 views
+10

通過Gmail郵件插件獲取電子郵件內容

1

我試圖讓Wmail(https://imgur.com/a/9h1ij)的gmail內容(body)得到上述錯誤。通過Gmail郵件插件獲取電子郵件內容

「拒絕訪問:不允許爲全面進入郵件」

Logger.log(mail.getPlainBody()); 
+0

請加[MCVE。 –

沙发
0
1

沒有看到你的代碼,這在我看來,你需要在你
「appsscript.json」,包括文件的正確範圍。

// This scope allows you to: 'View your email messages and settings' 
"oauthScopes": ["https://www.googleapis.com/auth/gmail.readonly"] 

// This scope gives you full access to your Gmail - 'Read, send, delete, and manage your email' 
"oauthScopes": ["https://mail.google.com/"] 

在這裏看到的範圍文檔:https://developers.google.com/identity/protocols/googlescopes#gmailv1