django ImportError: cannot import name list_route - python

Im trying to add a new endpoint by marking it with #list_route but when i try to import if :
from rest_framework.decorators import list_route
It cant find it. Do i need to install something for this to work (I'm new to django)?

When upgrading to higher versions, you might hit this question again.
list_route has been deprecated in favor of #action(detail=False)
More info in the release 3.8 announcement

The list_route decorator is present in version 3.1.3.
See: https://github.com/tomchristie/django-rest-framework/blob/3.1.3/rest_framework/decorators.py
Follow the instructions on https://github.com/tomchristie/django-rest-framework to install Django REST Framework properly.
To install version 3.1.3, run: pip install djangorestframework==3.1.3

Related

Import "rest_framework_swagger.views" could not be resolved

I wanted to implement swagger in Django rest framework, for that I install django-rest-swagger and register in setting.py but while importing in url.py it show error:-
"Import "rest_framework_swagger.views" could not be resolved.
How can I use rest_framework_swagger?
You should be calling this way.
Example :
from rest_framework_swagger.views import get_swagger_view
Instead of get_swagger_view call the view you require.
There could be many reasons but the truth is you shouldn't be using a project that's read-only for over 2.5 years.
Try drf-yasg or drf-spectacular instead.
Anyway, if you installed the lib you're talking about with
pip install django-rest-swagger
it should be available in your environment. Make sure you see it in pip freeze.

Django import Error(from extras.plugins import PluginConfig)

I'm new to Django and I try to develope a plugin for NextBox using this framework. To get familliar with it I'm using documentation from NextBox for this. My Problem is that I try to import a class as shown in the tutorial I get an Error that the package is unkown. When I want to install the package via PyCharm it seems to be the wrong one. Maybe someone of you can help me?
Doc: https://netbox.readthedocs.io/en/stable/plugins/development/
from extras.plugins import PluginConfig
class NextBoxUIConfig(PluginConfig):
In the IDE it says that extras is unkown after installing the package, .plugins is unkown as well as PluginConfig
The Solution is that the plugin has to be installed using $ python setup.py develop for development purposes. To install the plugin is necessary to have local netbox version installed. After using the command the name of the plugin has to be added to the netbox file configuration.py:
PLUGINS = [
'plugin_name',
]
But be sure to use the same venv you use to run netbox when installing the plugin with the listed command. After that the IDE will probably say it doesn't know what extras.something is. But it's installed and netbox will recognize when the plugin uses some netbox specific classes.
For more information use the netbox documentation:
https://netbox.readthedocs.io/en/stable/plugins/

How to import SlackWebHookOperator in Airflow?

I want to integrate Slack alert messages when a task fail in Airflow with SlackWebHookOperator. I have issue with the import of the operator.
In this tutorial (https://medium.com/datareply/integrating-slack-alerts-in-airflow-c9dcd155105) the author mentions there are 2 ways to achieve this. The first implementation is using slack legacy tokens which can be deprecated anytime and the second is using slack webhook which is the implementation I want. The author mentions to install slack dependencies, quoted by the author "Remember to install slack dependencies pip install apache-airflow[slack]" but this doesn't install SlackWebHookOperator as the import throws a “Cannot find reference slack_webhook_operator in init.py” error. Is there any other installation I am missing?
from airflow.contrib.operators.slack_webhook_operator import SlackWebHookOperator
I expect the SlackWebHookOperator to be able to be referenced.
I have tried installing slackclient dependency but it didn't installed SlackWebHookOperator as I cannot reference it.
SlackWebHookOperator is not available
For Airflow 2.x
airflow.contrib.operators.slack_webhook_operator has been deprecated.
You'd first have to install apache-airflow-providers-slack:
pip install apache-airflow-providers-slack
and finally import SlackWebhookOperator:
from airflow.providers.slack.operators.slack_webhook import SlackWebhookOperator
from airflow.providers.slack.operators.slack_webhook import SlackWebhookOperator

I'm getting error when trying to import reserve from urlresolver

when i try to import reverse in my models.py file with the following line: from django.core.urlresolvers import reverse i'm getting this error :ImportError: No module named 'django.core.urlresolvers.I'm learning django from youtube ,and here is the url of the video that i'm watching : https://www.youtube.com/watch?v=eouZwgKuA5k.How can i fix it?
This case, you imported reverse as follows:
from django.core.urlresolvers import reverse
Upgrade your Django version, use the following command
pip install --upgrade django
and then try again.
From Django 1.10+, the import has changed to:
from django.urls import reverse
However, the old import should still work in Django 1.10 and 1.11.
If the old import is giving you an error, that suggests that either your Django install is broken, or you have installed the master branch of Django (which will become 2.0). I would avoid using the master branch.
If possible, use the same Django version that the tutorial was written for, otherwise you might hit more problems like this. If the tutorial was written for Django < 1.8 then I would avoid it, as it is out of date.

Django docutils not working

I'm trying to enable docutils for django on windows 7. I've enabled the links in urls.y and settings.py and downloaded and installed the latest snapshot of docutils. However every time I try to access the documentation link in the admin I get a page asking me to install docutils.
Any ideas?
Thanks
I guess django tries to do
import docutils
And this fails. Django catches the exception and displayes this message to you.
Please try to get the real exception. You could insert the above line in one of your views:
def myview(request, ...):
import docutils
I hope django shows you the ImportError. Post it here, if still can't fix it.
Did you restart the Django server? Django has to restart to recognize the newly installed admindocs.
any chance you missed importing the admin in the urls.py?
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
You might have installed the docutils module in the virtual env/path.
Uninstall it from the virtual path and re-install it in the global python installation folder. That should solve the problem.
Note: Do not install django-docutils, but just simply docutils

Categories

Resources