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.
Related
I installed django_facebook (django-facebook==6.0.3). I am using Django 1.11.
I got an error:
File "path/lib/python3.5/site-packages/django_facebook/urls.py", line 4, in <module>
from django.conf.urls.defaults import patterns, url
ImportError: No module named 'django.conf.urls.defaults'
I was tring solved this problem with:
try:
from django.conf.urls import include, url
except ImportError:
from django.conf.urls.defaults import include, url
but without success.
Please for hint.
django.conf.urls.defaults was removed in Django 1.6, which was many years ago, and the django-facebook package you're using has the following message in its README (which was committed two years ago):
Django and Facebook are both rapidly changing at the moment. Meanwhile, I'm caught up in a startup and don't have much spare time. The library needs a good round of testing against the latest python, django and facebook graph API.
Unless you're willing to dive deep into the package's code, I'd recommend looking for another solution. It sounds like the author is looking for someone to help maintain it. Good luck!
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.
I am trying to use the oauth2app library inside my Django app. I've tried installing the library several ways (easy_install, pip, pip via a requirements file, etc.), and every time it installs just fine. Also every time I can import the library from the Django shell (manage.py shell).
However, when I try to use a view from the library:
(r'^oauth2/token/?$', 'oauth2app.token.handler'),
I get a "No module named oauth2app" import error. I've tried comparing the Python path from the Django debug page to the one from "print sys.path" inside the shell, and the seem to be the same, so I can't for the life of me figure out why one works and the other doesn't.
Can anyone help explain what's going on? I thought the Django shell was an equivalent environment to the Django instance ...
Nevermind, it looks like this was just a case of bad documentation on the library's site; when I changed the urls.py line to:
from oauth2app import token
...
(r'^oauth2/token/?$', token.handler),
it worked, sigh.
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
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/