Skip to content

Instantly share code, notes, and snippets.

View manjurulhoque's full-sized avatar
🏠
Working from home

Manjurul Hoque Rumi manjurulhoque

🏠
Working from home
View GitHub Profile
class LogoutView(RedirectView):
"""
Provides users the ability to logout
"""
url = '/login'
def get(self, request, *args, **kwargs):
auth.logout(request)
messages.success(request, 'You are now logged out')
return super(LogoutView, self).get(request, *args, **kwargs)
class Login(FormView):
"""
Provides the ability to login as a user with a username and password
"""
success_url = '/'
form_class = UserLoginForm
template_name = 'accounts/form.html'
extra_context = {
'title': 'Login'
class Register(CreateView):
model = User
form_class = UserRegistrationForm
template_name = 'accounts/form.html'
success_url = '/'
extra_context = {
'title': 'Register'
}
For python3 you would need to use
>>> exec(open('myscript.py').read())
or
import os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
django.setup()
# now your code can go here...
djangoapp/
__init__.py
models.py
...
templatetags/
__init__.py
custom_tags.py
Note:: After adding a new template tags module, you will need to restart
the Django development server in order to use the new template tags and filters.
import {withRouter} from 'react-router'
class Nav extends Component {
render () {
const { match, location, history } = this.props
return <h2>The Nav</h2>
}
}
public static String getDate(long time) {
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
cal.setTimeInMillis(time);
return DateFormat.format("EEE, dd/MM/yyyy", cal).toString(); // EEE is for day of the week
}