What is the difference between "'pages.apps.PagesConfig'" and "pages"? - django

It seems there are two ways to register a Django app (say, pages) in INSTALLED_APPS (in file 'settings.py'):
INSTALLED_APPS = [
pages, #option 1
pages.apps.PagesConfig, #option 2
]
Both seem to work with simple apps. But are there any differences between pages.apps.PagesConfig and pages?

Per user #riterix on Reddit who responded to my inquiry:
"The second one gives you the ability to load custom things... Like signals,...
For example you want to load some settings from db after accounts app load when a user logged in through signals.
NB : We used the second method in our project to load currency, metrics,... As a sessions variables based on the user country after he successfully logged in."

Related

Handling Django Registrations for Duplicate Entries

Question PART 1:
Project => App => forms.py
![User Creation Form using default Django Structure]
Project => App => urls.py
![URL Routes defined in urls.py of Django App]
Project => App => views.py
![User Authentication using default Django Structure]
Instead of using SQLite, I am using MongoDB Database and the entries are being stored in the auth_user table but I wanna get rid of duplicate entries (i.e. same username/email). If the user enters a same username/email, the page gives a DatabaseError Exception which I believe is handled by Django itself.
Question PART 2:
Project => settings.py
![Have included MessageTags into settings.py]
Also how to give specific redirect locations to messages in Django !? Once the user completes registration, the success message is displayed and he is redirected to the login page to access the dashboard and other features. But when the user logs in successfully, he is redirected to the dashboard but the Success Message is being displayed when he logs out (in the logout page).
Approach PART 1:
Can I, using try catch, handle the exception and allow the user to change the entered values to something unique and get his details saved into the database !?
Approach PART 2:
Sometimes the messages are appearing onto different pages than specified pages while using render/redirect for views.py functions(i.e routes). I tried redirecting each message to specific routes but I guess it overwrites to the last render/redirect route.
Regards,
Joe.

How to use Social-Auth-Django-App with Facebook's https://m.me/

I tried using hyperlink and supplied it with my actual Facebook Username and it's working. But the problem is my actual Facebook Username is different from the Username provided by Social-Auth-App-Django. So I tried User ID instead but it's not working either.
By the way what I'm trying to do is an online shopping website and when a user clicks the hyperlink, he/she will be redirected to the seller's Facebook Messenger account to start a conversation.
This is the first line of code that I tried which is working.
Send Message to Seller
And this is the code I used using Social-Auth-App's provided data:
Send Message to Seller
And I also tried this:
Send Message to Seller
Any idea how I can use Facebook's m.me/ using the provided data by Social-Auth-App-Django? Or if you can suggest me other ways other than m.me/ I will greatly appreciate it. Thank you very much!
First Go To Setting.py And Put This Code End Of All Codes:
AUTHENTICATION_BACKENDS = [
'social_core.backends.facebook.FacebookOAuth2',
]
Second Go To FaceBook Developer In This Address :
https://developers.facebook.com
And Make One Account There.
After go To My Apps And Then Click On Create App And Then Put Your Website Name ((Attention...If You Use Your Local Host You Need To Put One Domain Name For Your Local Ip)) And Your Email And Click On Create App ID And In Your Dashboard Looking For Facebook Login And Click On Set Up .
And Then In First Step In Web Window Put Your WebSite Name For Local Host For Example Put mysite.com:8000/ And Click On Save And Other Options Just Cross .
Now In Your Dashboard On The Left Side Click On Setting And Then Basic If You See Your APP ID And Your APP SECRET Put This Two In Your Settings.py After That Last Code .
SOCIAL_AUTH_FACEBOOK_KEY = 'Put Your App Id Code Here'
SOCIAL_AUTH_FACEBOOK_SECRET = 'Put Your App Secret Code Here'
If You Want To Take User's Email Also You Can You This As Well .
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
Now In You Dashboard Go To Settings And After Go To Basic An In Field App Domains Put Your Website Name Also Go To Settings After Advanced And Put Website Name In Domain Manager With CLick On Add a Domain .
Now Again In Dashboar Go In Products+ Part And Click On Facrbook Login After Settings And Check These Option Be Active(Yes) :
• Client OAuth Login
• Web OAuth Login
• Enforce HTTPS
• Embedded Browser OAuth Login
And IN This Form Your Are Now Also Go In This Field Valid OAuth Redirect URIs And Put This URL :
exapmle.com/social-auth/complete/facebook/
And Put Your Button In Your Website Page That Have This Login Auth :
<li>
Sign in with Facebook
</li>

authenticate with different table in django and not User

hello I have created a table register_Recruiter which has email and password as two of its column. Now to authenticate, from front end ( React) I am sending a post request containing email and password.But I am not able to do that.I tried looking for tutorials but no luck. Do help!!
PS: new to django -rest-framework
This is more connected with Django itself. I guess, you need to add your new table into Django settings AUTH_USER_MODEL=YOUR_NEW_USER_TABLE

Odoo website, Creating a signup page for external users

How can I create a signup page in odoo website. The auth_signup module seems to do the job (according to their description). I don't know how to utilize it.
In the signup page there shouldn't be database selector
Where should I store the user data(including password); res.users or res.partner
you can turn off db listing w/ some params in in odoo.cfg conf
db_name = mydb
list_db = False
dbfilter = mydb
auth_signup takes care of the registration, you don't need to do anything. A res.user will be created as well as a partner related to it.
The pwd is stored in the user.
User Signup is a standard feature provided by Odoo, and it seems that you already found it.
The database selector shows because you have several PostgresSSQL databases.
The easiest way is to set a filter that limits it to the one you want:
start the server with the option --dbfilter=^MYDB$, where MYDBis the database name.
User data is stored both in res.userand res.partner: the user specific data, such as login and password, are stored in res.user. Other data, such as the Name is stored in a related res.partner record.

Multiple installs of Django - How to configure transparent multiplex through the webserver (Lighttpd)?

This question flows from the answer to:How does one set up multiple accounts with separate databases for Django on one server?
I haven't seen anything like this on Google or elsewhere (perhaps I have the wrong vocabulary), so I think input could be a valuable addition to the internet discourse.
How could one configure a server likeso:
One installation of Lighttpd
Multiple Django projects running as FastCGI
The Django projects may be added/removed at will, and ought not to require restarting the webserver
Transparent redirection of all requests/responses to a particular Django installation depending on the current user
I.e. Given Django projects (with corresponding FastCGI socket):
Bob (/tmp/bob.fcgi)
Sue (/tmp/sue.fcgi)
Joe (/tmp/joe.fcgi)
The Django projects being started with a (oversimplified) script likeso:
#!/bin/sh
NAME=bob
SOCKET=/tmp/$NAME.fcgi
PROTO=fcgi
DAEMON=true
/django_projects/$NAME/manage.py runfcgi protocol=$PROTO socket=$SOCKET
daemonize=$DAEMON
I want traffic to http://www.example.com/ to direct the request to the correct Django application depending on the user that is logged in.
In other words, http://www.example.com should come "be" /tmp/bob.fcgi if bob is logged in, /tmp/joe.fcgi if joe is logged in, /tmp/sue.fcgi if sue is logged in. If no-one is logged in, it should redirect to a login page.
I've contemplated a demultiplexing "plexer" FastCGI script with the following algorithm:
If the cookie $PLEX is set, pipe request to /tmp/$PLEX.fcgi
Otherwise redirect to login page (which sets the cookie PLEX based on a many-to-one mapping of Username => PLEX)
Of course as a matter of security $PLEX should be taint checked, and $PLEX shouldn't give rise to any presumption of trust.
A Lighttpd configuration would be likeso (though Apache, Nginx, etc. could be used just as easily):
fastcgi.server = ( "plexer.fcgi" =>
( "localhost" =>
(
"socket" => "/tmp/plexer.fcgi",
"check-local" => "disable"
)
)
)
Input and thoughts, helpful links, and to know how to properly implement the FastCGI plexer would all be appreciated.
Thank you.
Here's roughly how I solved this:
In lighttpd.conf
$SERVER["socket"] == "localhost:81" {
include_shell "/opt/bin/lighttpd_conf.py"
}
And corresponding lighttpd_conf.py:
#!/usr/bin/python
import fileinput
ACCOUNT_LIST_FILE = "/opt/servers/account_list.txt"
for user in fileinput.input(ACCOUNT_LIST_FILE):
print """
$HTTP[\"url\"] =~ \"^/%s/\" {
scgi.server = ( \"/\" =>
(
(
\"socket\" => \"/tmp/user-socket-%s.scgi\",
\"check-local\" => \"disable\",
)
)
)
}
""" % (user, user)
Where ACCOUNT_LIST_FILE contains a number of accounts, e.g.
abc1
abc2
abc3
The server will map http://example.com/abc1 to /tmp/user-socket-abc1.scgi, where presumably a Django instance for user abc1 is talking SCGI.
One must obviously perform some sort of taint checking on the names of accounts (I generate these).