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
Related
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.
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.
Versions:
Python 3.5.1
Django 1.10
django-rosetta 0.7.13
The installation guide tells you to add the following to your project's settings.py:
from django.conf import settings
if 'rosetta' in settings.INSTALLED_APPS:
urlpatterns += patterns('',
url(r'^rosetta/', include('rosetta.urls')),
)
However, this just results in an error:
NameError: name 'patterns' is not defined
Searching for that problem reveals that one apparently has to import it:
from django.conf.urls import patterns
But still it doesn't work.
ImportError: cannot import name 'patterns'
This function was removed in django 1.10. However, one can add the rosetta urls conditionally using this approach:
from django.conf import settings
if 'rosetta' in settings.INSTALLED_APPS:
urlpatterns.append(url(r'^rosetta/', include('rosetta.urls')))
However, if you try to access rosetta at the url http://127.0.0.1:8000/rosetta/ you might be surprised to find that you still get a 404 Page not found.
So it seems that the included patterns are not working properly. But they are. The problem is that there's a hidden requirement that one must be logged in when accessing the rosetta page (maybe with a staff/super user?). So, simply go to http://127.0.0.1:8000/admin/, log in, and then go to the rosetta url again. Now it should work.
The installation does note this, sort of:
Because Rosetta requires write access to some of the files in your
Django project, access to the application is restricted to the
administrator user only (as defined in your project’s Admin interface)
How does it know you are an administrator if you are not logged in? It doesn't, and apparently instead of giving an informative error, it ignores the rosetta urls entirely.
I am trying to add the django package know as Django-scheduler in to my project. Please walk me through it by steps as how I have to install it and then run in my project.
Thanks in advance.
I am one of the contributors of the django-scheduler project
for install django scheduler on your env please ejecute the following steps:
pip instal django-scheduler
add to your django settings.py the scheduler app (watch out the "r" on project name here!):
INSTALLED_APPS += ('schedule',)
I just noticed that you need to put as installed app "schedule" instead of "scheduler" (this is going to be fixed in next version.
add to TEMPLATE_CONTEXT_PROCESSORS:
"django.core.context_processors.request"
then sync your db with:
python manage.py syncdb
please provide an example of how you are using the django-scheduler or how you are importing it (I will edit this answer asap).
I'm a Django amateur, and have problems getting django-registration to work. I followed the installation instructions on their website, but for someone like me these instructions are not 100% clear as to what I should be doing. Here is what I've done:
I installed the oauth2 and python-openid packages using pip. I then copied the facebook.py file from the facebook-python-sdk package to my main django app directory. (As I write this, I'm wondering whether this file should be copied to the socialregistration app directory? Does it make a difference?)
I copied the socialregistration directory to my django project's directory.
I added socialresgitration to my INSTALLED_APPS setting.
To add socialregistration.urls to my urls.py file, I added the following line (not sure if this is correct, since the instructions don't give details):
(r'^social/', include('socialregistration.urls')),
I added the facebook API key and secret key to my settings
I added socialregistration.auth.FacebookAuth to AUTHENTICATION_BACKENDS.
I added socialregistration.middleware.FacebookMiddleware to MIDDLEWARE_CLASSES.
Finally I added the three facebook tags they give in the instructions to one of my templates.
When I then load my website, I get the folllowing error:
Caught AttributeError while rendering: Please add the django.core.context_processors.request context processors to your settings.TEMPLATE_CONTEXT_PROCESSORS set
So, what can I do? I thought installation would be quite simple, but apparently this is not the case. ANY help would be appreciated!
Oh, BTW, I'm using Django 1.2.1 and Python 2.6.
Thanks!
Please add the django.core.context_processors.request context processors to your settings.
Have you done that?
You'll need to change TEMPLATE_CONTEXT_PROCESSORS to include django.core.context_processors.request.
I've found the problem. When my view renders the template, it needs to pass the RequestContext to the template.
return render_to_response('my_template.html', my_data_dictionary, context_instance=RequestContext(request))
Source: http://lincolnloop.com/blog/2008/may/10/getting-requestcontext-your-templates/