Import "rest_framework_swagger.views" could not be resolved - python

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.

Related

How to uninstall django-rest-swagger?

Is there a simple or elegant way to uninstall django-rest-swagger on Windows 10? I've recently started developing API's and creating documentation. I found a tutorial that used the django-rest-swagger app. After installing the app and doing more reading, I discovered that it was deprecated, and the developer's GitHub page recommends using drf-yasg.
I tried using "pip uninstall django-rest-swagger," and that echoed back that the app was uninstalled. But, when I went into the virtual environment folder of the project, all the package folders were still there. I also tried "pipenv uninstall django-rest-swagger", but it returned "pipenv is not recognized..." I spent a few hours reading the app docs, and googling "how to remove/ uninstall django-rest-swagger." However, I didn't find anything useful.
Eventually, I gave up, and decided to do it the hard way. I manually deleted all the installed files. Fortunately, I hadn't updated my requirements.txt, so, I knew what was originally installed. While this solution worked, it was somewhat time consuming.
Does django-rest-swagger have an internal uninstall command? And does anyone know why "pip uninstall" didn't remove the app folders?
Thanks
Just enable your virtualenv probably doing:
. /path/to/virtualenv/bin/activate
Then:
pip uninstall django-rest-swagger
Then go to settings.py and remove or comment the following line:
INSTALLED_APPS = [
...
#'rest_framework_swagger',
...
]
And finally remove or comment in views.py the import and code related with swagger library:
from django.conf.urls import url
#from rest_framework_swagger.views import get_swagger_view
#schema_view = get_swagger_view(title='Pastebin API')
urlpatterns = [
# url(r'^$', schema_view),
...
]
That's it.

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/

Error in template flask run AndreiD/Flask-Easy-Template

Good Morning!
I am a beginner in the python / flask world ... I found this template and found it complete and simple, good for beginners and with some interesting features.
I just can not run this template. It has some packages that do not install by pip (pycrypto==2.6.1, python-cloudfiles==1.7.11, python-loaders==0.2.3).
Was this a reason? Can anybody help me?
I need some help to run this template.
enter image description here
Thanks!
This project is unmaintained, please try this one instead.
For your question, flask.ext.foo is the old way to import extension and it is removed in Flask 1.0. If you want to fix it, try the methods below:
Method 1: Fix old import statements
Find these lines in application/__init__.py:
from flask.ext.cache import Cache
from flask.ext.sqlalchemy import SQLAlchemy
change them to:
from flask.cache import Cache
from flask.sqlalchemy import SQLAlchemy
Method 2: Use a virtual enviroment
Everything will be ok if you use the pinned version in the project's requirement file. Just create a virtual enviroment with virtualenv, pipenv, poetry, venv etc, activate the virtual enviroment, then install dependency from the requirements.txt file.

django ImportError: cannot import name list_route

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

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