Error arises again and again\

48 views
Skip to first unread message

niranjan shukla

unread,
Aug 1, 2019, 3:39:04 AM8/1/19
to Django users
I am using the Django 1.11 but I always encounter the same error. if you know anything to this then tell me, brother,


from common.decorators import ajax_required
      ModuleNotFoundError: No module named 'common

胡超

unread,
Aug 1, 2019, 3:40:52 AM8/1/19
to django...@googlegroups.com
Maybe you need pip the pack;

在 2019年8月1日,下午3:39,niranjan shukla <niranjan...@gmail.com> 写道:

ModuleNotFoundError

niranjan shukla

unread,
Aug 1, 2019, 3:43:08 AM8/1/19
to Django users
pip install django-common

or 

pip install common

胡超

unread,
Aug 1, 2019, 3:45:08 AM8/1/19
to django...@googlegroups.com
Y

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2956cea0-785d-4e09-ad11-615e48d04f1b%40googlegroups.com.

niranjan shukla

unread,
Aug 1, 2019, 3:49:25 AM8/1/19
to Django users
AFTER INSTALLING THE DJANGO-COMMON AND I AM USING PYTHON 3.6

 
from common.decorators import ajax_required
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\common\decorators.py", line 61
    except Exception, ex:
                    ^
SyntaxError: invalid syntax

胡超

unread,
Aug 1, 2019, 3:57:50 AM8/1/19
to django...@googlegroups.com
You can uninstall Django-common and install common. Try it.

在 2019年8月1日,下午3:49,niranjan shukla <niranjan...@gmail.com> 写道:

Python

niranjan shukla

unread,
Aug 1, 2019, 4:01:05 AM8/1/19
to Django users
views.py


from django.http import JsonResponse
from django.views.decorators.http import require_POST
from common.decorators import ajax_required
from .models import Contact

@ajax_required
@require_POST
@login_required
def user_follow(request):
    user_id = request.POST.get('id')
    action = request.POST.get('action')
    if user_id and action:
        try:
            user = User.objects.get(id=user_id)
            if action == 'follow':
                Contact.objects.get_or_create(
                    user_from=request.user,
                    user_to=user)
            else:
                Contact.objects.filter(user_from=request.user,
                                       user_to=user).delete()
            return JsonResponse({'status':'ok'})
        except User.DoesNotExist:
            return JsonResponse({'status':'ko'})
    return JsonResponse({'status':'ko'})









when I install the common then 

ERROR: 

File "C:\Users\user\Desktop\allauth1 - Copy\users\views.py", line 133, in <module>
    from common.decorators import ajax_required
ModuleNotFoundError: No module named 'common.decorators'


 

胡超

unread,
Aug 1, 2019, 4:07:53 AM8/1/19
to django...@googlegroups.com
When you install Django-common , exam the function ajax_required  . Try to  fond error.

Im sorry for my bad English.

--
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...@googlegroups.com.

niranjan shukla

unread,
Aug 1, 2019, 4:19:37 AM8/1/19
to Django users

# -*- coding: utf-8 -*-
"""
Contains view's decorators which automates common tasks.
"""

import traceback

from django.shortcuts import render_to_response
from django.template import RequestContext

from common.http import HttpResponseJson

def render_to(template):
    """
    Render view's output with ``template`` using ``RequestContext``.

    If decorated view returns dict object then wrap it in RequestContext and
    render the template.

    If decorated view returns non dict object then just return this object.

    Args:
        :template: path to template
    
    Example::

        @render_to('blog/index.html')
        def post_list(request):
            posts = Post.objects.all()
            return {'posts': posts,
                    }
    """

    def decorator(func):
        def wrapper(request, *args, **kwargs):
            output = func(request, *args, **kwargs)
            if not isinstance(output, dict):
                return output
            else:
                ctx = RequestContext(request)
                return render_to_response(template, output, context_instance=ctx)
        return wrapper
    return decorator


def ajax(func):
    """
    Convert views's output into JSON.

    Decorated view should return dict object.

    If ``request.method`` is not ``POST`` then deny the request.

    If view raises Exception then return JSON message with error description.
    """

    def wrapper(request, *args, **kwargs):
        if request.method == 'POST':
            try:
                response = func(request, *args, **kwargs)
            except Exception, ex:
                response = {'error': traceback.format_exc()}
        else:
            response = {'error': {'type': 403, 'message': 'Accepts only POST request'}}
        if isinstance(response, dict):
            return HttpResponseJson(response)
        else:
            return response
    return wrapper


def ajax_get(func):
    """
    Convert views's output into JSON.

    Decorated view should return dict object.

    If view raises Exception then return JSON message with error description.
    """

    def wrapper(request, *args, **kwargs):
        try:
            response = func(request, *args, **kwargs)
        except Exception, ex:
            response = {'error': traceback.format_exc()}
        if isinstance(response, dict):
            return HttpResponseJson(response)
        else:
            return response
    return wrapper


def disable_cache(func):
    def decorated(*args, **kwargs):
        resp = func(*args, **kwargs)
        resp['Pragma'] = 'no-cache'
        resp['Expires'] = '0'
        resp['Cache-Control'] = 'no-cache, no-store, must-revalidate'
        return resp
    return decorated
 
Error is 

胡超

unread,
Aug 1, 2019, 4:50:08 AM8/1/19
to django...@googlegroups.com
The answer is change for  python2.7 & python3.6 .
This pack is worked  in python2.7 
Could you try fond the pack worked in python3.6

Lim Kai Wey

unread,
Aug 1, 2019, 4:56:57 AM8/1/19
to django...@googlegroups.com
如果有需要, 我能帮忙翻译,看你俩聊好像有点痛苦。

Translation:
I can help translate if you guys want... I don’t mind translating 

Regards,
Kai Wey

胡超

unread,
Aug 1, 2019, 5:02:01 AM8/1/19
to django...@googlegroups.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...@googlegroups.com.

胡超

unread,
Aug 1, 2019, 5:06:14 AM8/1/19
to django...@googlegroups.com
多谢了。兄弟 ,请翻译 :
问题是由于python2.7 和python3.6 之间的版本差异导致的。
这位小兄弟在使用python3.6 的版本。加载一个python2.7 版本的包。django-common。 需要寻找这个包的python3.6 版本, 如果没有这个版本的话 就需要寻找其他的解决方案。

在 2019年8月1日,下午4:56,Lim Kai Wey <limk...@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...@googlegroups.com.

Lim Kai Wey

unread,
Aug 1, 2019, 5:09:50 AM8/1/19
to django...@googlegroups.com
哈哈哈 我真不介意,大家都来这学习嘛。互相帮忙是应该的。

Translation:
I really don’t mind translating, this is where we all learn. It’s a must to help each other out.

Ps. The three letters he said translate that I’m a nice person 

Regards,
Kai Wey


niranjan shukla

unread,
Aug 1, 2019, 5:12:02 AM8/1/19
to Django users
Yes translate and share with us please and how I can talk with you if I got another error

Lim Kai Wey

unread,
Aug 1, 2019, 5:17:06 AM8/1/19
to django...@googlegroups.com
请翻译 :
问题是由于python2.7 和python3.6 之间的版本差异导致的。
这位小兄弟在使用python3.6 的版本。加载一个python2.7 版本的包。django-common。 需要寻找这个包的python3.6 版本, 如果没有这个版本的话 就需要寻找其他的解决方案。

Translates:
The problem is due to the difference between the Python version 2.7 and 3.6. Because you’re using Python 3.6, you’ll have to have another Python 2.7’s package.  The Django-Common package will search for its package that is in Python 3.6, if there aren’t any package in this version then you’ll have to look for another solution.

Regards,
Kai Wey

Message has been deleted

niranjan shukla

unread,
Aug 1, 2019, 5:21:52 AM8/1/19
to Django users
I want to build the follow system in my website how i can do that
    beacuse i am using that ajax so that i can building follow system
 

Lim Kai Wey

unread,
Aug 1, 2019, 5:29:35 AM8/1/19
to django...@googlegroups.com
翻译:
他说,他需要用那系统来设计他网站。他都是靠Ajax 设计那网站的。他都在这学的 

Ps. I just wanna say please use propose grammar so I can translate more accurately. Thanks

Regards,
Kai Wey

Lim Kai Wey

unread,
Aug 1, 2019, 5:31:50 AM8/1/19
to django...@googlegroups.com
他还有问要怎么弄才行。

胡超

unread,
Aug 1, 2019, 5:34:45 AM8/1/19
to django...@googlegroups.com
多谢了 兄弟:
我找了一篇帖子 主要讲如何在django 中使用ajax 来实现前端和后端的通信。
可以参考一下这篇帖子
当然这篇帖子中有一部分内容是中文。但是代码逻辑是相同的。

帮我翻译。幸苦了兄弟。

在 2019年8月1日,下午5:31,Lim Kai Wey <limk...@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...@googlegroups.com.

Lim Kai Wey

unread,
Aug 1, 2019, 5:41:39 AM8/1/19
to django...@googlegroups.com
我找了一篇帖子 主要讲如何在django 中使用ajax 来实现前端和后端的通信。
可以参考一下这篇帖子
当然这篇帖子中有一部分内容是中文。但是代码逻辑是相同的。

Translate:
I found an article, that mainly teaches the backend and frontend between Django and Ajax. Although the article is in mandarin, but the logic of the code is there and same. You can view it as a reference.

niranjan shukla

unread,
Aug 1, 2019, 5:43:56 AM8/1/19
to Django users
I want to build user following system in Django for my social site
I want to build user following system in Django for my social site 

Lim Kai Wey

unread,
Aug 1, 2019, 5:52:29 AM8/1/19
to django...@googlegroups.com
他说,他要在他社交网站弄个 用户关注
Reply all
Reply to author
Forward
0 new messages