I have create test application with pythn-social-aut in which I login using facebook.
When i click in the facebook link it redirect me to facebook login page. It works correctly
After test app I integrate in application but when i click on the facebok login link it give me 404 error. Even I check step by step but found whats the reason.
I inspect the link its href=/login/facebook/ is correct but not redirect me to facebook login page
here my code
under my main urls.py i have paste
urlpatterns = patterns('',
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^admin/', include(admin.site.urls)),
(r'^tinymce/', include('tinymce.urls')),
(r'^comments/', include('django.contrib.comments.urls')),
(r'^', include('app.urls')),
url(r'^(?i)login/$', login, {'template_name': 'login.html'}),
url(r'^(?i)logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Inside my app.urls
urlpatterns = patterns('',
url(r'^socialcheck/$', 'app.views.socialCheck'),
)
100% working in the test app but in main project when i integrate it give 404 error when i click on link
It is a very good chance that your problem is in the urls.py code which you doesn't show. I suspect that some of the urls catches the ^/login/([^/]+)/ pattern but doesn't handle the /login/facebook/ path.
Try to move the social urls to the top of your urls.py. Set it as the first item of the patterns():
urlpatterns = patterns('',
url('', include('social.apps.django_app.urls', namespace='social')),
...
)
Related
I have a blog made in django in a VPS. The blog is working fine but to access it I have to write the url example.com/blog/
What I'm trying is to make an automatic redirection so when a user enters example.com/ it automatically redirects to example.com/blog/
The project is set under apache.
This is my the configuration in myproject/urls.py:
urlpatterns = [
url(r'^blog/', include('blog.urls', namespace="blog")),
url(r'^admin/', include(admin.site.urls)),
]
This is the configuration of myproject/blog/urls.py that right now is formed by a post list and a post detail:
urlpatterns = patterns('',
# Index
url(r'^(?P<page>\d+)?/?$', ListView.as_view(
model=Post,
paginate_by=5,
),
name='index'
),
# Individual posts
url(r'^(?P<pub_date__year>\d{4})/(?P<slug>[a-zA-Z0-9-]+)/?$', DetailView.as_view(
model=Post,
),
name='post'
),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I already tried to add a .htaccess with different configurations but it's not working.
Is there a way to redirect from django?
If you're sure that you want that / to redirect to /blog/ for that you can create a temporary index view and redirect the response to /blog/
url(r'^', temp_index, name='index'),
def temp_index(request):
return HttpResponseRedirect('/blog/')
If you want that / must show /blog then replace
url(r'^blog/', include('blog.urls', namespace="blog")), with
url(r'^', include('blog.urls', namespace="blog")),
I am working on django project. I am kinda learning it. So my project has user login logout functionality and I wanna add profile based user management system too. So what I wanna do is if someone is trying to access this link, I wanna show user profile
siteURL/username
so my project's urls.py file has these codes,
urlpatterns = [
# url(r'^admin/', include(admin.site.urls)),
# Robots.txt request
url(r'^robots.txt', TemplateView.as_view(template_name="robots.txt", content_type="text/plain")),
# Profile related requests
url(r'^$', include('UserProfile.urls')),
# Home page request
url(r'^$', include('Homepage.urls')),
# Accounts related requests
url(r'^accounts/', include('Accounts.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
# handling error requests for 403, 404, 500 etc
handler404 = 'errorPages.views.error404'
handler500 = 'errorPages.views.error500'
and my UserProfile app has url.py file and codes are,
urlpatterns = [
# User Profile related requests
url(r'^(?P<uname>.+?)/update$', User_Profile_Update.as_view()),
]
and my class file's codes are,
class HC_User_Profile_Update(TemplateView):
def get(self, request, *args, **kwargs):
return render(request, "user_profile/profile_update.html"),
My homepage app has urls.py file and codes are,
urlpatterns = [
#Home page request
url(r'^$', HomePage.as_view()),
]
and homepage class file,
class HomePage(TemplateView):
def get(self, request):
if request.user.is_authenticated():
return render(request, "homepage/home.html", {'uname': request.user.uname})
else:
return render(request, "homepage/home.html")
I am getting 404 error that Url not found. So can anyone tell me what is wrong in my urls? For now, I just wanna check that the url is rendering the html page or not. And url I am trying to access right now is
sitename/username/update
Thank you for your time.
Try to remove $ from your project's urls.py file. Update your urls.py file as
urlpatterns = [
# url(r'^admin/', include(admin.site.urls)),
# Robots.txt request
url(r'^robots.txt', TemplateView.as_view(template_name="robots.txt", content_type="text/plain")),
# Profile related requests
url(r'^', include('UserProfile.urls')),
# Home page request
url(r'^$', include('Homepage.urls')),
# Accounts related requests
url(r'^accounts/', include('Accounts.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
# handling error requests for 403, 404, 500 etc
handler404 = 'errorPages.views.error404'
handler500 = 'errorPages.views.error500'
Hope it will work.
My website runs with no problem when DEBUG is set to true. but i get requested url not found error when i run the server in production setting. the admin page is fine.
this is my project urls.py:
urlpatterns = patterns('',
url(r'^', include('photography.urls')),
url(r'^admin/', include(admin.site.urls)),
# url(r'^$', 'photography.views.hello_world', name='home'),
)
this is my app urls.py:
urlpatterns = patterns('photography.views',
url(r'^$', views.index, name='index'),
url(r'^albums/(?P<slug>[a-zA-Z0-9-]+)/$', views.photos_by_location, name='photos_by_location'),
)
For testing purpose, i added a hello world view and it gets rendered with commented line in project urls.py. so I guess my way of including app urls is not really good when DEBUG is false . Is there a way to include my app urls that works in production setting?
Any help would be appreciated. thanks.
Update:
tried url(r'^/', include('photography.urls')), with a / after ^. didnt work either.
I have created a small project like this structure..
|-mysite
|-polls
|---static
|-----polls
|-------css
|---------images
|-------images
|-------js
|---templates
|-----polls
|-templates
|---admin
Here In polls is the app and now i am getting output with this url http://127.0.0.1:8000/polls/
In main folder i.e mysite folder in urls.py i have code like this..
urlpatterns = patterns('',
url(r'^polls/',include('polls.urls',namespace="polls")),
url(r'^admin/', include(admin.site.urls)),
Now in polls folder in urls.py code is..
urlpatterns = patterns('',
url(r'^$',views.index, name = 'index'),
}
Now i want to get the page like main website address like.. http://127.0.0.1:8000/
How to get?
Thanks.
Can you change what you have here
url(r'^polls/',include('polls.urls',namespace="polls")),
to
url(r'^', include('polls.urls', namespace="polls")),
Now the reason is this:
Django urls uses regex. In your example, you're telling django to catch your polls app, beginning from the url as localhost:8000/polls/
Learn more: https://docs.djangoproject.com/en/dev/topics/http/urls/
Even in your root project urls.py, you've got this:
# Examples:
# url(r'^$', 'Toolkit.views.home', name='home'), #this will match url of the type localhost:8000
# url(r'^blog/', include('blog.urls')), # this will match url of the type localhost:8000/blog/
Just look sharp!
I started going through tut but then got stuck on the page.
tutorial page 3 - django
I exactly followed the tut to the point where it asks to goto localhost:8000/polls/.
There starts the problem, it is not working, states an error
Please, tell how to correct the error.
That page is a 404 page not found. This suggests to me that you have either not configured your URL's correctly or it's missing.
/project/urls.py
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
)
Where polls.urls points to your app URL at /polls/urls.py
So now in your polls/url.py add the index as described.
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index')
)
https://docs.djangoproject.com/en/1.6/intro/tutorial03/#write-your-first-view